我正在尝试在地图上制作给定位置的街道全景图。有时,全景图可以正常工作,并将位置作为全景图的位置,有时则仅显示带控件的灰色屏幕。为了解决这个问题,我尝试使用StreetViewService.getPanoramaByLocation()。从此函数返回的LatLng非常接近已经工作的全景图位置的LatLng,但是当我将此输入用作位置时,全景图始终是灰色的。我做了很多研究,仍然无法解决问题。
这是我的代码:
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
}
});
}
任何帮助将不胜感激!谢谢!
答案 0 :(得分:5)
我这样做与你略有不同。如果状态为“ok”,我只会创建StreetViewPanorama
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();
}
});