两个地址之间的距离 [英] Distance between two addresses
问题描述
我正在使用php编写一个预订网站,我需要一个库或一个远程服务(类似于google maps api)来计算两个地址之间的距离。
理想情况下,我更喜欢道路距离,但我并不在乎距离是多远。
你能帮我吗?
非常感谢您的宝贵意见,欢迎您提供帮助。
Google Maps API - Directions 是一个不错的开始。使用网址发送请求模式:
http://maps.google.com/maps/ api / directions / xml?origin = [FROM_ADDRESS]& destination = [TO_ADDRESS]& sensor = false
// [FROM_ADDRESS]是开始
的Google可识别地址// [TO_ADDRESS]是一个Google可识别的地址,用于结束
示例 - 我如何前往卡内基音乐厅?来自S ONY音乐娱乐公司)
起始地址:美国纽约州纽约市麦迪逊大道550号
结束地址:纽约州纽约市第八大道881号, United States
Google的XML Directions路径为
http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New + York,+ NY,+ United + States& sensor = false
结果是:
< DirectionsResponse>
< status>确定< / status>
<路线>
< summary> E 57th St< / summary>
< leg>
< step>
< travel_mode> DRIVING< / travel_mode>
< start_location>
< lat> 40.7612400< / lat>
< lng> -73.9731300< / lng>
< / start_location>
< end_location>
< lat> 40.7622900< / lat>
< lng> -73.9723600< / lng>
< / end_location>
<折线>
wdxwF` {nbMqEyC
<级别> BB< /级别>
< / polyline>
<持续时间>
<值> 9< /值>
< text> 1分钟< / text>
< /持续时间>
< html_instructions>
头< b>东北< / b> on< b> Madison Ave< / b>朝向< b> E 56th St< / b>
< / html_instructions>
<距离>
<值> 133< /值>
< text> 436 ft< / text>
< /距离>
< / step>
< step>
< travel_mode> DRIVING< / travel_mode>
< start_location>
< lat> 40.7622900< / lat>
< lng> -73.9723600< / lng>
< / start_location>
< end_location>
< lat> 40.7655300< / lat>
< lng> -73.9800500< / lng>
< / end_location>
<折线>
< points> ikxwFfvnbMgS`o @< / points>
<级别> BB< /级别>
< / polyline>
<持续时间>
<值> 148< /值>
< text> 2分钟< / text>
< /持续时间>
< html_instructions>
转到< b>左< / b>在第二个交叉街上< b> E 57th St< / b>
< / html_instructions>
<距离>
<值> 741< /值>
< text> 0.5 mi< / text>
< /距离>
< / step>
< step>
< travel_mode> DRIVING< / travel_mode>
< start_location>
< lat> 40.7655300< / lat>
< lng> -73.9800500< / lng>
< / start_location>
< end_location>
< lat> 40.7651800< / lat>
< lng> -73.9803000< / lng>
< / end_location>
<折线>
q_ywFhfpbMdAp @< / points>
<级别> BB< /级别>
< / polyline>
<持续时间>
<值> 39< /值>
< text> 1分钟< / text>
< /持续时间>
< html_instructions>
转到< b>左< / b>在< b> 7th Ave< / b> < div style =font-size:0.9em>目标位于左侧< / div>
< / html_instructions>
<距离>
<值> 45< /值>
< text> 148英尺< / text>
< /距离>
< / step>
<持续时间>
<值> 196< /值>
< text> 3分钟< / text>
< /持续时间>
<距离>
<值> 919< /值>
< text> 0.6 mi< / text>
< /距离>
< start_location>
< lat> 40.7612400< / lat>
< lng> -73.9731300< / lng>
< / start_location>
< end_location>
< lat> 40.7651800< / lat>
< lng> -73.9803000< / lng>
< / end_location>
550 Madison Ave,New York,NY 10022,USA< / start_address>
< end_address> 881 7th Ave,New York,NY 10019,USA< / end_address>
< / leg>
<版权>地图数据©2010 Google,Sanborn< / copyrights>
< overview_polyline>
< points> wdxwF` {nbMqEyCgS`o @ dAp @< / points>
<级别> B @?B< / levels>
< / overview_polyline>
< / route>
< / DirectionsResponse>
因此,这两点之间最快的路线将包含以下细节:
-
持续时间
DirectionsResponse>路线>腿>持续时间>值
-
纯文本的持续时间
DirectionsResponse> route> leg> duration> text
-
本地测量的基本单位距离(英尺或米)
DirectionsResponse>路线>腿>距离>值
-
本地测量的纯文本距离(英里或公里) b
$ bDirectionsResponse>路线>腿>距离>文本
I'm writing a booking web site in php and I would need a library or a remote service (similar to google maps api) that calculate the distance between 2 addresses.
Ideally I prefer road distance but I don't care too much about what kind of distance is.
Can you help me?
Thank you very much, every help will be welcome.
Google Maps API - Directions is a good place to start.
Sending off a request using the URL Pattern:
http://maps.google.com/maps/api/directions/xml?origin=[FROM_ADDRESS]&destination=[TO_ADDRESS]&sensor=false
// [FROM_ADDRESS] is a Google-Recognisable address for the Start
// [TO_ADDRESS] is a Google-Recognisable address for the End
Example - "How do I get to Carnegie Hall? (From Sony Music Entertainment)"
Start Address: 550 Madison Avenue, New York, NY, United States End Address: 881 7th Avenue, New York, NY, United States
The URL for the XML Directions from Google would be
http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false
The result is:
<DirectionsResponse>
<status>OK</status>
<route>
<summary>E 57th St</summary>
<leg>
<step>
<travel_mode>DRIVING</travel_mode>
<start_location>
<lat>40.7612400</lat>
<lng>-73.9731300</lng>
</start_location>
<end_location>
<lat>40.7622900</lat>
<lng>-73.9723600</lng>
</end_location>
<polyline>
<points>wdxwF`{nbMqEyC</points>
<levels>BB</levels>
</polyline>
<duration>
<value>9</value>
<text>1 min</text>
</duration>
<html_instructions>
Head <b>northeast</b> on <b>Madison Ave</b> toward <b>E 56th St</b>
</html_instructions>
<distance>
<value>133</value>
<text>436 ft</text>
</distance>
</step>
<step>
<travel_mode>DRIVING</travel_mode>
<start_location>
<lat>40.7622900</lat>
<lng>-73.9723600</lng>
</start_location>
<end_location>
<lat>40.7655300</lat>
<lng>-73.9800500</lng>
</end_location>
<polyline>
<points>ikxwFfvnbMgS`o@</points>
<levels>BB</levels>
</polyline>
<duration>
<value>148</value>
<text>2 mins</text>
</duration>
<html_instructions>
Turn <b>left</b> at the 2nd cross street onto <b>E 57th St</b>
</html_instructions>
<distance>
<value>741</value>
<text>0.5 mi</text>
</distance>
</step>
<step>
<travel_mode>DRIVING</travel_mode>
<start_location>
<lat>40.7655300</lat>
<lng>-73.9800500</lng>
</start_location>
<end_location>
<lat>40.7651800</lat>
<lng>-73.9803000</lng>
</end_location>
<polyline>
<points>q_ywFhfpbMdAp@</points>
<levels>BB</levels>
</polyline>
<duration>
<value>39</value>
<text>1 min</text>
</duration>
<html_instructions>
Turn <b>left</b> at the 3rd cross street onto <b>7th Ave</b> <div style="font-size:0.9em">Destination will be on the left</div>
</html_instructions>
<distance>
<value>45</value>
<text>148 ft</text>
</distance>
</step>
<duration>
<value>196</value>
<text>3 mins</text>
</duration>
<distance>
<value>919</value>
<text>0.6 mi</text>
</distance>
<start_location>
<lat>40.7612400</lat>
<lng>-73.9731300</lng>
</start_location>
<end_location>
<lat>40.7651800</lat>
<lng>-73.9803000</lng>
</end_location>
<start_address>550 Madison Ave, New York, NY 10022, USA</start_address>
<end_address>881 7th Ave, New York, NY 10019, USA</end_address>
</leg>
<copyrights>Map data ©2010 Google, Sanborn</copyrights>
<overview_polyline>
<points>wdxwF`{nbMqEyCgS`o@dAp@</points>
<levels>B@?B</levels>
</overview_polyline>
</route>
</DirectionsResponse>
So, the quickest route between those two points will have details of:
Duration in Seconds
DirectionsResponse > route > leg > duration > value
Duration in Plain Text
DirectionsResponse > route > leg > duration > text
Distance in Base Unit of Local Measurements (Feet or Metres)
DirectionsResponse > route > leg > distance > value
Distance in Plain Text for Local Measurement (Miles or Kilometers)
DirectionsResponse > route > leg > distance > text
这篇关于两个地址之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!