Sunday, April 19, 2009

Solution to generating markers along a route at a regular interval

I found this neat javascript extension for the google map api. Here is the link:

http://econym.org.uk/gmap/epoly.htm

You specify the distance and give it a polyline and it returns an array of points along the route.



map.setCenter(new GLatLng(42.351505,-71.094455), 15);
var directionsPanel = document.getElementById("directions_div");
var directions = new GDirections(map, directionsPanel);
var address = "from: trenton, nj to: philadelphia, pa";

directions.load(new_address);
if (directions == null){
alert("Error: directions object is null");
return;
}

var pl = directions.getPolyline();

if (pl == null){
alert("Error: polyline object is null");
return;
}

var points = pl.GetPointsAtDistance(1609.344);

if (points == null){
return;
}

for (var i=0; i
map.addOverlay(new GMarker(points[i]));
}



No comments:

Post a Comment