How do I make a distance traveled Maps (yahoo/google) feature
I've been asked to make a feature that works with one of the popular map APIs. This feature would take a Start Point, End Point and a distance value and would generate a map showing the progress from the Start Point to the End Point.
For example, if the Start Point was Seattle, the End Point was Chicago and the distance value was 1000 miles, the map API would be used to create a map showing both Seattle and Chicago, with a line about 1/3rd of the way there.
Ideally, the mapping API used would be a publically available API available without cost. Seems easy, right? I'm not sure where to start. I would appreciate all input at this stage.
There are no comments for this entry.
Add Comment Subscribe to CommentsWhile I haven't done that specifically I would recommend the yahoo direction. Its map isn't as good looking, but the api is easier, and if you use GEOLocation for anything, its more accurate (for me anyway).
@Dan, are you talking about an actual route? Following roads, or are you just talking about straight line as the crow flies?
@Chris, Nice Work.. I like that interaction
@Joshua I'm looking at the Yahoo AS3 map right now. It does look pretty clean.
@Fred There are a few examples of drawing line overlays on Yahoo and Google. They look pretty easy to implement, but I would prefer an actual route.
I started working on an AIR app and I chose the yahoo map component. All in all I have been very happy with it. Be careful though for 2 reasons. the first being I think I read its for non-commercial use and you need to get a license for "real" apps. Second being the limit the number of requests, and I have not yet found a way to cache the map tiles. So every zoom and pan requires a re-request of all the tiles (as best I can tell) which means you have a lot of requests really quick,
Ping me if you want to visit about it.
@Dan are you going to let yahoo/google determine your route? Allowing for traffic and road closing and such? or do you want to click/enter the route yourself?
Either way, I think you will come to the same result. Here is a very high level look at what you will need to do.
You will have a set of line segments that form a polyline, loop over them in order until the sum of all parts is greater than the distance traveled. At which point you take the current segment calc the arc between points calc the point along the arc at the remainder of distance from the previous segment.
A couple things to consider:
When using lat/lng to calculate the distance between point you need to consider the curve of the earth, this is done with the Haversine Formula.
Depending on your final usage and the amount of data transmitted you should consider which side to store the entire route on, assuming you want to push/pull updates.
Consider using Google's PolyLine Encoder to keep the transfer size down, the encoder also has a utility for culling the line at increasing zoom levels. (you do not want to draw 600 polylines when zoomed out if you do not need to.
Hi - I found this post via the search "map api distance on a line" - I'm interested in doing nearly the same thing, except perhaps I'd have a completed route and place multiple markers on that route for step-by-step progress of an object on that route. I'm playing around with the Yahoo Flash MAP api now, but I was wondering how your project went and if you have any tips.
Many thanks,
Ben
Yahoo! Maps had a Distance class that will calculate this for you. I have an example posted on blog that uses this technique.