I am passing lat and lng variables and display google sreet view in a div. The problem is that when the StreetView is unavilable then nothing is displayed. I would like to c
Update for Google Maps JavaScript API v3.25+:
In v3.25 (current release version) and v3.26 (current experimental version), getPanoramaByLocation() is still available but not documented anymore.
@arthur-clemens's accepted answer still works, but use getPanorama() with a StreetViewLocationRequest instead if you want better compatibility:
var gstService = new google.maps.StreetViewService();
gstService.getPanorama({
location: new google.maps.LatLng(40.7140, -74.0062),
source: google.maps.StreetViewSource.OUTDOOR
}, function (data, status) {
if (status === google.maps.StreetViewStatus.OK) {
// OK
} else {
// error or no results
}
});
Omit source in the StreetViewLocationRequest if you do not want the panorama search to be limited to outdoor ones.