Calculation route length

I have a map with about 80 annotations. I would like to do 3 things.

1) From my current location, I would like to know the actual distance to this position. Not a linear distance.

2) I want to show a list of all annotations, but for each annotation (with lon / lat) I would like to know the actual distance from my position to that position.

3) I would like to find out the closest annotation to my execution using a route distance. Non-linear distance.

I think the answer to all three of these questions will be the same. But keep in mind that I don't want to create a route, I just want to know the distance to the annotation.

Hope someone can help me.

Best regards, Paul Pilen

+2


a source to share


3 answers


I think that, as stated earlier, your request will be extremely heavy on the Google Maps API if you do exactly what you say. Do you need all this information at once? It might be enough at first to only ask for some distances based on some heuristic or user needs.

To get the distance, you can use the Google Maps object GDirections

... as stated here (at the bottom of the page there is < Routes and steps ", with an extended example .

" The GDirections object also supports multi-point directions, which can be constructed using the GDirections.loadFromWaypoints() method. This method takes an array of textual input addresses or textual lat/lon points. Each separate waypoint is computed as a separate route and returned in a separate GRoute object, each of which contains a series of GStep objects.

"



Using the Google Maps API on an iPhone shouldn't be too hard, and I think your question doesn't cover it, but if you want some basic example you can take a look at this one and scroll to the answer.

Good luck!

+1


a source


From what I understand from your post, I believe you are looking for the Haversine formula . Luckily for you there are a number of Objective-C implementations , although writing your own is trivial after the formula in front of you.



I originally removed this because I didn't notice that you didn't want linear distance at first, but I'm putting it back in if you decide the approximation is good enough at that particular user experience point.

+2


a source


Calculating route distance up to about 80 locations will definitely be computing power-intensive in the Google part, and I can't imagine that you would be able to execute these requests in the Google Maps API, is it possible to do it on a mobile device, without a strict phone limit line or speed limits on the server.

Unfortunately, calculating route distance rather than geometric distance is a very expensive computation involving a lot of area data — data you almost certainly don't have. This means, unfortunately, that this is not something Core Location or MapKit can help you with.

What problem are you trying to solve, exactly? There may be other heuristics other than distance between routes that you can use to approximate some distance ranking.

0


a source







All Articles