Road distance,Actual distance between two places

2020-02-12 18:31发布

问题:

I want to calculate the driving distance between two locations [the user's specified locations], before user starts the driving. I used many formulas and getDistanceFrom in CLLocation also, but I am not able to get the perfect the driving distance between those locations.

There is much difference in actual and calculated distance.

Please help me to calculate the driving distance between two locations. How can I use Google Maps API to calculate the driving distance ?

I have already use the regexkitlite to show the road path on Google Maps between the two place. However I can't calculated the path distance.

If you have any code/link, please send it to me.

Thanks in advance....

回答1:

See directions API of Google Maps

You have just to make a HTTP request:
http://maps.googleapis.com/maps/api/directions/output?parameters

Answer could be json or xml. You will find the distance in the answer



回答2:

If you have two LatLongs you can calculate the direct distance between them; however, since you want driving directions (not as the crow flies) you'll need access to street-center-lines, so you can calculate the distance for each "leg" of the trip.

Google Maps may provide driving directions along with route distance, you'll need to check the documentation for that specific functionality.

edit

On a second look, it appears this may not be available on the API (as of 2006), but a work-around is posted here: http://groups.google.com/group/Google-Maps-API/msg/4dc2fad4f74e3314



回答3:

Using Core Location API it will only give you the distance between two point in a straight line - most roads aren't, and hence the distance will be wrong.