谷歌地图街景全景显示错误

4
我会尽心尽力为您翻译。以下是需要翻译的内容:

我正在尝试在地图上制作给定位置的街景全景图。有时,全景图可以正常工作,位置也能正确显示,但有时只会显示灰色屏幕和控件。为解决此问题,我尝试使用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
            }
        });
    }

任何帮助都将不胜感激!谢谢!

google.maps.LatLng(latitude, longitude) 是创建 LatLng 对象的格式... - Ramesh Kotha
1个回答

6

我和你的做法略有不同。只有当状态为“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();
    }
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接