使用Google Maps API V3以编程方式更新StreetView

时间:2012-11-12 01:58:06

标签: javascript google-maps google-maps-api-3

我想知道是否有可能以编程方式不断更新Google地图街景API的坐标?谢谢和代码段可能会有所帮助

2 个答案:

答案 0 :(得分:7)

获得StreetViewPanorama后,您可以通过编程方式更新位置或观点,如下所示:

var panorama = map.getStreetView();// or new google.maps.StreetViewPanorama(div);

// update position of StreetView
panorama.setPosition(new google.maps.LatLng(42.345573,-71.098326));

// update the point of view
panorama.setPov({
  heading: 34,
  pitch: 10,
  zoom: 1
});

答案 1 :(得分:0)

创建div地图容器

<div id="panrama" style="width: 400px; height: 400px"></div>

使用JavaScript自动旋转:

var     pano;
var     latlng = new google.maps.LatLng(38.897526, -77.0370613);

var panoOptions = {
    position: latlng,
    pov: {
        heading: 0,
        pitch: 0
    }
};

pano = new google.maps.StreetViewPanorama(
    document.getElementById('panorama'), 
    panoOptions);

window.setInterval(function() {
    var pov = pano.getPov();
    pov.heading += 0.2;
    pano.setPov(pov);
}, 10);

示例:Virtual Tour White House

致谢:theoryapp.com