Google地图可以动态缩放不同的位置 [英] Google maps dynamically zooming in different locations

查看:113
本文介绍了Google地图可以动态缩放不同的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要创建一个方法,使相机在某个位置放大5秒,然后动态更改为我设置的位置。我已经实现了缩放功能,它可以动态缩放每5000毫升,但是任何人都可以帮助我如何改变位置暂停5秒,然后重新缩放到该位置?非常感谢。这里是我的代码。

  var map; 

函数initialize(){
var latlng = new google.maps.LatLng(52.474,-1.868);

var myOptions = {
zoom:1,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};

var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);

var curZoom = 1;
var zoomInterval;

//创建具有缩放级别的地图curZoom
// ...

zoomInterval = setInterval(function(){
curZoom + = 1;
map.setZoom(curZoom);
if(curZoom === 6){
clearInterval(zoomInterval);
}
},5000);
}

google.maps.event.addDomListener(window,'load',initialize);


解决方案使用 map.setCenter )在你的 setInterval()函数中。您可能有预定义的位置,因此您需要在 setCenter()函数中使用它们。



地点:

  var places = [[52,-1],[52,-2],[53,-1] ,[53,-2],[54,-1],[54,-2]]; 

zoomInterval = setInterval(function(){
var lat = places [curZoom] [0];
var lng = places [curZoom] [1];
map.setCenter(new google.maps.LatLng(lat,lng));
map.setZoom(curZoom); //或静态值,如5,7或其他
if(curZoom == = 6){
curZoom = 0;
} else {
curZoom ++;
}
},5000);


Hi I need to create a method where the camera zooms for 5 seconds in a location and then dynamically changes to a location that I set. I ve implementing the zooming function where it zooms dynamically every 5000 ml but anyone can help on how I can make it for instance change location pause for 5sec and then rezoom to that location? Many thanks. here is my code.

var map;

function initialize() {
   var latlng = new google.maps.LatLng(52.474, -1.868);

   var myOptions = {
      zoom: 1,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };

   var bikeLayer = new google.maps.BicyclingLayer();
   bikeLayer.setMap(map);

   var curZoom = 1;
   var zoomInterval;

   // create map with zoom level curZoom
   // ...

   zoomInterval = setInterval(function () {
      curZoom += 1;
      map.setZoom(curZoom);
      if (curZoom === 6) {
         clearInterval(zoomInterval);
      }
   }, 5000);
}

google.maps.event.addDomListener(window, 'load', initialize);

解决方案

Use map.setCenter() in your setInterval() function. You probably have predefined locations, so you need to use them in setCenter() function.

Example usage with predefined locations:

var places = [ [52, -1], [52, -2], [53, -1], [53, -2], [54, -1], [54, -2] ];

zoomInterval = setInterval(function () {
   var lat = places[curZoom][0];
   var lng = places[curZoom][1];
   map.setCenter(new google.maps.LatLng(lat, lng));
   map.setZoom(curZoom); // or a static value like 5, 7 or something else
   if (curZoom === 6) {
      curZoom = 0;
   } else {
      curZoom++;
   }
}, 5000);

这篇关于Google地图可以动态缩放不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆