Google maps api 3 谷歌地图视口自动调整

Google maps api 3 谷歌地图视口自动调整,google-maps-api-3,Google Maps Api 3,我在这里发现了@Chad Killingsworth创建的一些不错的动画路线,我只是想问一下是否可以自动调整地图的视口,以便我们可以看到路线的走向 function initialize() { var mapOptions = { zoom: 14, center: new google.maps.LatLng("54.32216667","10.16530167"), mapTypeId: google.maps.MapTypeId.TERRAIN };

我在这里发现了@Chad Killingsworth创建的一些不错的动画路线,我只是想问一下是否可以自动调整地图的视口,以便我们可以看到路线的走向

function initialize() {
  var mapOptions = {
    zoom: 14,
    center: new google.maps.LatLng("54.32216667","10.16530167"),
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var path_start = new Array();
  var path_end = new Array();

  path_start.push(new google.maps.LatLng("54.32216667","10.16530167"));
  path_end.push(new google.maps.LatLng("54.32216667","10.16530167"));

  // lots of other points

  path_start.push(new google.maps.LatLng("54.36457667","10.12173333"));
  path_end.push(new google.maps.LatLng("54.36457833","10.121745"));

  var carPolyline = new google.maps.Polyline({
    map: map,
    geodesic : true,
    strokeColor : '#FF0000',
    strokeOpacity : 1.0,
    strokeWeight : 2
  });
  var carPath = new google.maps.MVCArray();
  for ( var i = 0; i < path_start.length; i++) {
    if(i === 0) {
      carPath.push(path_start[i]);
      carPolyline.setPath(carPath);
    } else {
      setTimeout((function(latLng) {
        return function() {
          carPath.push(latLng);
        };
      })(path_start[i]), 100 * i);
    }
  }
函数初始化(){
变量映射选项={
缩放:14,
中心:新google.maps.LatLng(“54.32216667”,“10.16530167”),
mapTypeId:google.maps.mapTypeId.TERRAIN
};
var map=new google.maps.map(document.getElementById('map-canvas'),
地图选项);
var path_start=新数组();
var path_end=新数组();
path_start.push(新的google.maps.LatLng(“54.32216667”,“10.16530167”);
path_end.push(新的google.maps.LatLng(“54.32216667”,“10.16530167”);
//还有很多其他的观点
path_start.push(新的google.maps.LatLng(“54.36457667”,“10.12173333”);
path_end.push(新的google.maps.LatLng(“54.36457833”,“10.121745”);
var carPolyline=新的google.maps.Polyline({
地图:地图,
测地线:正确,
strokeColor:“#FF0000”,
笔划不透明度:1.0,
冲程重量:2
});
var carPath=new google.maps.MVCArray();
对于(变量i=0;i
提前感谢。

添加:

map.setCenter(latLng);
到绘制多段线的代码

  var carPath = new google.maps.MVCArray();
  for ( var i = 0; i < path_start.length; i++) {
    if(i === 0) {
      carPath.push(path_start[i]);
      carPolyline.setPath(carPath);
    } else {
      setTimeout((function(latLng) {
        return function() {
          carPath.push(latLng);
          map.setCenter(latLng);
        };
      })(path_start[i]), 100 * i);
    }
  }
var carPath=new google.maps.MVCArray();
对于(变量i=0;i

您所说的“自动调整地图的视口,以便我们可以看到其前进方向”是什么意思?您希望地图保持在最近添加的点的中心,并具有更近的缩放级别吗?