Google displays StreetViewPanorama error message

I am trying to take a street panorama of a specific location on a map. Sometimes a panorama works fine with the location as the position of the panorama, while in other cases only a gray screen with controls is displayed. To solve this problem, I am trying to use StreetViewService.getPanoramaByLocation (). The returned LatLng from this function is VERY close to the LatLng of the panorama locations that are already working, but the panorama is ALWAYS gray when I use this input as a position. I have done a lot of research and still can not solve the problem.

Here is my code:

function init() { var location = new google.maps.LatLng(<%=id%>); map = new google.maps.Map(document.getElementById("map_canvas"), { center: location, zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); marker = new google.maps.Marker({ map: map, position: location }); var client = new google.maps.StreetViewService(); client.getPanoramaByLocation(location, 49, function(result, status) { if (status == "OK" ) location = result.location.latLng; }); myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), { position: location, pov: { pitch: -10, heading: 0, zoom: 1 } }); } 

Any help would be greatly appreciated! Thanks!

+4
source share
1 answer

I do it a little differently than you. I only create StreetViewPanorama if the status is "ok"

 var sv = new google.maps.StreetViewService(); sv.getPanoramaByLocation(streetViewLocation, 50, function(data, status) { if (status == 'OK') { //google has a streetview image for this location, so attach it to the streetview div var panoramaOptions = { pano: data.location.pano, addressControl: false, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL } }; var panorama = new google.maps.StreetViewPanorama(document.getElementById(strMapCanvasID), panoramaOptions); } else{ //no google streetview image for this location, so hide the streetview div $('#' + strMapCanvasID).parent().hide(); } }); 
+5
source

Source: https://habr.com/ru/post/1392091/


All Articles