我正在尝试在地图上绘制给定位置的街道全景图。有时,全景图可以很好地将位置作为全景图的位置,而有时它只显示带有控件的灰色屏幕。为了解决这个问题,我尝试使用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
}
});
}任何帮助都将不胜感激!谢谢!
发布于 2012-01-21 01:39:51
我做这件事的方式和你略有不同。我只在状态为'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();
}
});https://stackoverflow.com/questions/8945283
复制相似问题