javascript - Google Maps Api :set the center of map to different coordinates after rendering -


i want change center of google map after time interval can focus on areas of whole continent having markers showing restaurants branches. have rendered map markers. having problem changing center looping through list of latitude , longitude. trying this.

var lat[];         var lang[];              function movetolocation(){                 var center = new google.maps.latlng(lat, lng);                 map.panto(center);             }               setinterval(movetolocation, 3000);   

from related question: google maps dynamically zooming in different locations

proof of concept fiddle

code snippet:

var map;    function initialize() {    map = new google.maps.map(      document.getelementbyid("map_canvas"), {        center: new google.maps.latlng(37.4419, -122.1419),        zoom: 8,        maptypeid: google.maps.maptypeid.roadmap      });      var places = [      [52, -1],      [52, -2],      [53, -3],      [53, -5],      [54, -4],      [54, -6]    ];      var index = 0;    zoominterval = setinterval(function() {      var lat = places[index][0];      var lng = places[index][1];      index = (index + 1) % places.length;      map.setcenter(new google.maps.latlng(lat, lng));      }, 5000);      }  google.maps.event.adddomlistener(window, "load", initialize);
html,  body,  #map_canvas {    height: 100%;    width: 100%;    margin: 0px;    padding: 0px  }
<script src="https://maps.googleapis.com/maps/api/js"></script>  <div id="map_canvas"></div>


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -