The reason for this is that POV overlooking the street is by default the direction the truck was in when the image was taken (figure). You need to find the location of the truck and the location of the house and calculate the βheadingβ from first to second , and then set the location of the street view in relation to the truck with the course you specified
// adrloc=target address // svwloc=street-view truck location svwService.getPanoramaByLocation(adrloc,svwdst,function(dta,sts) { if(sts==google.maps.StreetViewStatus.OK) { var svwloc=dta.location.latLng; var svwhdg=google.maps.geometry.spherical.computeHeading(svwloc,adrloc); var svwmap=avwMap.getStreetView(); svwmap.setPosition(svwloc); svwmap.setPov({ heading: svwhdg, pitch: 0 }); svwMarker=new google.maps.Marker({ map:svwmap, position: adrloc }); svwmap.setVisible(true); } else { ... }
Another street view trick / trap is that you need to get the closest street view to the address place, repeatedly calling getPanoramaByLocation with increasing distance until you succeed or reach the maximum distance. I solve this with this code:
var SVW_MAX=100; // maximum street-view distance in meters var SVW_INC=10; // increment street-view distance in meters var svwService=new google.maps.StreetViewService(); // street view service var svwMarker=null; // street view marker // NOTE: avwMap is the aerial view map, code not shown ... resolveStreetView(avwMap.getCenter(),SVW_INC); ... var resolveStreetView=function(adrloc,svwdst) { svwService.getPanoramaByLocation(adrloc,svwdst,function(dta,sts) { if(sts==google.maps.StreetViewStatus.OK) { var svwloc=dta.location.latLng; var svwhdg=google.maps.geometry.spherical.computeHeading(svwloc,adrloc); var svwmap=avwMap.getStreetView(); svwmap.setPosition(svwloc); svwmap.setPov({ heading: svwhdg, pitch: 0 }); svwMarker=new google.maps.Marker({ map:svwmap, position: adrloc }); svwmap.setVisible(true); } else if(svwdst<SVW_MAX) { resolveStreetView(adrloc,svwdst+SVW_INC); } }); }
Lawrence dol
source share