Alex Rivera | Logout

How to add markers on Google Maps polylines based on distance along the line?

Asked 2010-04-23T11:29:07.373
17

I am trying to create a Google Map where the user can plot the route he walked/ran/bicycled and see how long he ran. The GPolyline class with it’s getLength() method is very helpful in this regard (at least for Google Maps API V2), but I wanted to add markers based on distance, for example a marker for 1 km, 5 km, 10 km, etc., but it seems that there is no obvious way to find a point on a polyline based on how far along the line it is. Any suggestions?

Edit
Report

1 Answer

3

Possibly the best approach would be to calculate where these points are.

As a basic algorithm you could iterate over all the points in the Polyline, and calculate the cumulative distance - if the next segment puts you over your distance, you can interpolate the point where the distance has been reached - then simply add a point of interest to your map for that.

answered 2010-04-23T11:38:44.083

Your Answer