google map viewport auto adjust -


i found nice animated route created @chad killingsworth in jsfiddle,i want ask if possible adjust automatically viewport of map can see route headed.

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();   ( var = 0; < 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);     }   } 

thank in advance.

add:

map.setcenter(latlng); 

to code drawing polyline.

  var carpath = new google.maps.mvcarray();   ( var = 0; < 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);     }   } 

updated fiddle


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -