简体   繁体   English

Google地图在不同位置动态缩放

[英]Google maps dynamically zooming in different locations

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. 嗨,我需要创建一种方法,使相机在某个位置变焦5秒钟,然后动态更改为我设置的位置。 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? 我已经实现了缩放功能,该功能每隔5000 ml动态缩放一次,但是任何人都可以帮助我实现例如将位置暂停5秒钟,然后再缩放到该位置吗? 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. setInterval()函数中使用map.setCenter() You probably have predefined locations, so you need to use them in setCenter() function. 您可能有预定义的位置,因此需要在setCenter()函数中使用它们。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM