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?
-
2Looking at what the web API does, a query for pano data either returns data properties OR an empty panorama. Example: Valid: http://cbk0.google.com/cbk?output=xml&oe=utf-8&cb_client=apiv3&v=4&ll=42.983787%2C-89.428062&callback=callback Invalid: http://cbk0.google.com/cbk?output=xml&oe=utf-8&cb_client=apiv3&v=4&ll=42.983787%2C-99.428062&callback=callback Should I just use this to verify whether it exists? – Osmund Oct 05 '10 at 16:20
4 Answers
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.

- 422
- 4
- 10
-
1Great idea! Even better, use connection.setRequestMethod("HEAD") and just test connection.getHeaderField("Content-Length"). Less data exchanged. – Pierre-Luc Paour Mar 27 '13 at 17:04
-
@shreks7 if street view is not available for any coordinates and we requested this file size=600x800 or even this 600x440. , then google API return different size according to the requested image . – nivritgupta Jun 27 '18 at 16:50
-
@shreks7 how we can identify if Panorama exits before launching street view , I only see one difference if Panorama is not available then API return us a file less then 10 KB . – nivritgupta Jun 27 '18 at 16:52
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.

- 986,068
- 189
- 2,389
- 2,491
-
2This won't let me know if there is an actual panorama available at a given location will it? As far as I see it will only tell me whether the StreetView activity exists. On devices with StreetView activity, I wind up with a black screen and a spinner that doesn't give any indication that a panorama exist for that geopoint. The Streetvew activity is still launched correctly though. I can query the above URL above to discover that data actually exists before launching the Activity via intent. There is no streetViewExists(Geopoint p) or some such function is there? – Osmund Oct 05 '10 at 17:58
-
1@Osmund: Whoops, sorry, I thought your concern was whether Streetview itself was available. There is no means to determine if a street view exists. – CommonsWare Oct 05 '10 at 18:05
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.

- 3,763
- 4
- 30
- 48
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);
}
});

- 1,054
- 1
- 11
- 22