Skip to content

Instantly share code, notes, and snippets.

@onnayokheng
Created December 10, 2013 08:28
Show Gist options
  • Save onnayokheng/7887345 to your computer and use it in GitHub Desktop.
Save onnayokheng/7887345 to your computer and use it in GitHub Desktop.
var departure = new google.maps.LatLng(-6.18049, 106.82638); //Set to whatever lat/lng you need for your departure location
var arrival = new google.maps.LatLng(-6.17770, 106.82141); //Set to whatever lat/lng you need for your arrival location
var line = new google.maps.Polyline({
path: [departure, departure],
strokeColor: "#FF0000",
strokeOpacity: 0.7,
strokeWeight: 2,
geodesic: true, //set to false if you want straight line instead of arc
map: map,
});
var step = 0;
var numSteps = 250; //Change this to set animation resolution
var timePerStep = 5; //Change this to alter animation speed
var interval = setInterval(function() {
step += 1;
if (step > numSteps) {
clearInterval(interval);
} else {
var are_we_there_yet = google.maps.geometry.spherical.interpolate(departure,arrival,step/numSteps);
line.setPath([departure, are_we_there_yet]);
}
}, timePerStep);
@drtobal
Copy link

drtobal commented Apr 21, 2016

How about a polyline with 4 coordinates in path?

@macro6461
Copy link

How can I get this to go around the streets? Right now it just jumps across everything. Is there a way to achieve the timed rendering but have it pivot at the polyline points rather than jump across?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment