How to calculate the driving distance between two points?

社会主义新天地 提交于 2019-12-11 18:30:59

问题


In my app I am getting the latitude , longitude co-ordinates of places using GeocodeService now I want to get distance between these places.

I've tried GetDistanceTo method to get the distance two location co-ordinates but it gives me stright distance.

How can I calculate driving distance between two locations?

thanks in advance


回答1:


To calculate the driving distance you'll have to use the Bing Routes API (or Google, but I assume you're using Bing Maps).

There's an example of using the api to find a driving route between two places here: http://msdn.microsoft.com/en-us/library/gg636957.aspx

The general call is: http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&wp.0=location1&wp.1=location2&avoid=minimizeTolls&key=BingMapsKey

You'll have to register for a Bing Maps API key, and then replace location1 and location2 with the locations you like.

The distance should be returned in travelDistance in the json or xml



来源:https://stackoverflow.com/questions/14831801/how-to-calculate-the-driving-distance-between-two-points

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