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....
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
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
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.
精彩评论