Road distance,Actual distance between two places

荒凉一梦 提交于 2019-12-18 07:02:09

问题


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.



来源:https://stackoverflow.com/questions/4144746/road-distance-actual-distance-between-two-places

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!