仅使用PHP计算两点之间的行驶距离(必应地图) [英] Calculating the driving distance between two points using PHP only (Bing maps)

查看:218
本文介绍了仅使用PHP计算两点之间的行驶距离(必应地图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想算出两点之间的距离.没有地图.没有JavaScript.就是距离.

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

我了解Google地图禁止这样做,这违反了他们的服务条款.但是Bing Maps没有此限制.

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.)在 http处注册Bing Maps密钥. ://www.bingmapsportal.com .密钥是长度约为64个字符的字母数字字符串,类似于:AtGYpcoIpC5zy0P2k4Bc4839b- = fLgbbnsp72T3ZrM0z7gAaMcjXlZPsKXghW

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.)然后,向Bing Maps Routes API(http://msdn.microsoft.com/en-us/library/ff701717.aspx)发出请求,以生成最多25个航点之间的路线.对于给定的示例,将您的Bing Maps密钥替换为以下URL:

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/路线?wp.1 =英国剑桥和wp.2 =英国纽卡斯尔安德莱姆教堂街& key = ENTERYOURBINGMAPSKEYHERE

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

3.)您将获得一个JSON响应,其中包含路线,转弯路线等详细信息,如以下所述:

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.

这篇关于仅使用PHP计算两点之间的行驶距离(必应地图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆