I have a button within an infobox. I want that button to switch to street view. The button gets triggered and switches to street view however my code below treats street view as an entirely separete entity to my google map which means I cannot zoom out back to map view and there is no visible marker on street view level:
var fenway = new google.maps.LatLng(this.marker[id].position.jb,this.marker[id].position.kb);
var panoramaOptions = {
position: fenway,
pov: {
heading: 34,
pitch: 10
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById("map-canvas"), panoramaOptions);
this.gmap.setStreetView(panorama);
How do I modify this so that streetview is triggered within the current map rather than creating an entirely separete instance?
This worked for me:
var streetViewMaxDistance = 100;
var point = new google.maps.LatLng(this.marker[id].position.jb,this.marker[id].position.kb);
var streetViewService = new google.maps.StreetViewService();
var panorama = this.gmap.getStreetView();
streetViewService.getPanoramaByLocation(point, streetViewMaxDistance, function (streetViewPanoramaData, status) {
if(status === google.maps.StreetViewStatus.OK){
var oldPoint = point;
point = streetViewPanoramaData.location.latLng;
var heading = google.maps.geometry.spherical.computeHeading(point,oldPoint);
panorama.setPosition(point);
panorama.setPov({
heading: heading,
zoom: 1,
pitch: 0
});
panorama.setVisible(true);
}else{
// no street view available in this range, or some error occurred
console.log("Sorry! Street View is not available.");
}
});