Calculating the driving distance between two points using PHP only (Bing maps)

独自空忆成欢 提交于 2020-01-01 21:37:09

问题


I'd like to work out the distance between two points. No map. No javascript. Just the distance.

I understand Google maps prohibits this and it's against their terms of service. But Bing Maps doesn't have this restriction.

I want to give the points in a general format, i.e "Cambridge" "Church Street, Newcastle"

How would I go about doing it? As basic as possible. It's for a mobile device.


回答1:


1.) Sign up for a Bing Maps key at http://www.bingmapsportal.com. A key is a alphanumeric string of around 64 characters in length, something like: AtGYpcoIpC5zy0P2k4Bc4839b-=fLgbbnsp72T3ZrM0z7gAaMcjXlZPsKXghW

2.) Then, make a request to the Bing Maps Routes API (http://msdn.microsoft.com/en-us/library/ff701717.aspx) to generate a route between up to 25 waypoints. For the example given, substitute your Bing Maps key into the following URL:

http://dev.virtualearth.net/REST/v1/Routes?wp.1=Cambridge, UK&wp.2=Church St, Newcastle-under-Lyme, UK&key=ENTERYOURBINGMAPSKEYHERE

3.) You'll get a JSON response containing details of the route, turn-by-turn directions etc. as described at: http://msdn.microsoft.com/en-us/library/ff701718.aspx. The total driving distance is given quite near the bottom of the response, called "travelDistance" (in this case,218.703). You can also choose what units this value is returned in by specifying the appropriate distanceUnit parameter when you first request the route.




回答2:


Is very simple:

http://dev.virtualearth.net/REST/V1/Routes/Walking?wp.0=11025%20NE%208th%20St%20Bellevue%20WA&wp.1=700%20Bellevue%20Way%20NE%20Bellevue WA&key=BingMapsKey

Ref : MSDN



来源:https://stackoverflow.com/questions/9856101/calculating-the-driving-distance-between-two-points-using-php-only-bing-maps

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