How to find out if a street view exists before launching Streetview intent

Running a Streetview object on a location does not guarantee that Streetview exists for that location. If Streetview does not exist, the user simply sees a black screen that rotates. Is there a way to programmatically check if it exists before launching the Streetview intent?

+4
source share
5 answers

Use PackageManager and queryIntentActivities() with Intent . If you return a list of 0 suitable actions, you know nothing that the device will process your request.

+5
source

To do this, you can use the Google Street View Image API to check if Google Street View exists or not.

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

It returns an image with a different file size when the street view in certain coordinates exists 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 exists.

+5
source

It will probably help, this is my publication on a similar issue. Determine the existence of the Google Streetview function

+1
source

I have not tested the Android API, but with the JavaScript API there is a StreetViewService class with the getPanoramaByLocation method. If there is no Street View in this place, it returns NO_RESULTS.

0
source

I will give you a snippet of my solution to check if a street view exists with my integration of streetview api images with googe images. Suppose you can use StreetViewStatus.Ok boolean for normal street viewing.

  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); } }); 
-1
source

All Articles