How to tell if a Streetview exists before launching Streetview intent

坚强是说给别人听的谎言 提交于 2019-11-28 01:29:52

问题


Launching a Streetview intent for a location doesn't guarantee that a Streetview exists for that location. If the Streetview doesn't exist, the user just sees a black screen that spins. Is there a way to programmatically check if it exists before launching the Streetview intent?


回答1:


Use PackageManager and queryIntentActivities() with your Intent. If you get back a list of 0 matching activities, you know nothing on the device will handle your request.




回答2:


A way to do that would be to use Google Street View Image API to check whether Google Street View exist or not.

https://developers.google.com/maps/documentation/streetview/

It returns an image with a different file size when Street View at a particular co-ordinates exist,than when it doesn't

http://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,%20-73.988354&fov=90&heading=235&pitch=10&sensor=false

You can compare these images and check if it exist or not.




回答3:


I've not checked the Android API but with the JavaScript API there is a StreetViewService class with a getPanoramaByLocation method. If there is no Street View at that location, it returns NO_RESULTS.




回答4:


i ll give you a snippet of my solution for checking if a streetview exists from my googe image api streetview image integration - guess you can use the StreetViewStatus.Ok boolean for ordinary streetview too.

  streetViewService.getPanoramaByLocation(latLng, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
            if (status === google.maps.StreetViewStatus.OK) {
                var img = document.createElement("IMG");
                img.src = 'http://maps.googleapis.com/maps/api/streetview?size=160x205&location='+ lat +','+ lng  +'&sensor=false&key=AIzaSyC_OXsfB8-03ZXcslwOiN9EXSLZgwRy94s';
                var oldImg = document.getElementById('streetViewImage');
                document.getElementById('streetViewContainerShow').replaceChild(img, streetViewImage);
            } else {
                var img = document.createElement("IMG");
                img.src = '../../images/ProfilnoProfilPicture.jpg';
                img.height = 205;
                img.width = 160;
                var oldImg = document.getElementById('streetViewImage');
                document.getElementById('streetViewContainerShow').replaceChild(img, streetViewImage);
            }
        });


来源:https://stackoverflow.com/questions/3865607/how-to-tell-if-a-streetview-exists-before-launching-streetview-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!