我的信息框中有一个按钮。我想要那个按钮切换到街景。该按钮被触发并切换到街景 View ,但是下面的代码将街景 View 视为与我的谷歌地图完全独立的实体,这意味着我无法缩小回 map View ,并且街景 View 级别上没有可见的标记:
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);
如何修改它以便在当前 map 内触发街景而不是创建一个完全独立的实例?
最佳答案
这对我有用:
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.");
}
});
关于google-maps - 用于切换到街景的信息框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16210571/