简体   繁体   English

如何通过谷歌地图与PHP获得步行或驾驶距离

[英]How to get walking or driving distance via google maps with php

I've worked with google maps before, but when implementing it, I've never found any documentation on how to get the exact distance between 2 given locations via Javascript or PHP. 之前我曾经使用谷歌地图,但在实施时,我从未找到任何关于如何通过Javascript或PHP获得2个给定位置之间的确切距离的文档。

1) It has to be the exact same distance shown on maps, not that formula that gives you the distance in a straight line from one geopoint to the other. 1)它必须是地图上显示的完全相同的距离,而不是那个公式,它给出了从一个地点到另一个地点的直线距离。

2) It has to be either PHP or Javascript 2)它必须是PHP或Javascript

3) It has to be Google maps, not virtual earth or anything similar. 3)它必须是谷歌地图,而不是虚拟地球或类似的东西。

Best thing I've come up with is sending a HTTP_GET request to google maps using a long URL with variables, which then returns a 200 code plus the HTML for the website. 我想出的最好的事情是使用带有变量的长URL向Google地图发送HTTP_GET请求,然后返回200个代码以及网站的HTML。 The distance is in there somewhere, just need to filter. 距离在某处,只需要过滤。

But that's resources intensive and load heavy. 但这是资源密集和负担沉重。

Does anybody know of a better way? 有人知道更好的方法吗?

EDIT: this is the function I'm talking about. 编辑: 是我正在谈论的功能。 The DLL isn't included in the regular zip file for windows, I found it as a part of the WAMPserver software. DLL没有包含在Windows的常规zip文件中,我发现它是WAMPserver软件的一部分。

This posting gives a way and a warning. 这个帖子提供了一种方法和警告。

To break it down you use google maps to query a URL like this 要将其分解,请使用谷歌地图查询这样的网址

http://maps.google.com/maps?q=from+A+to+B&output=kml http://maps.google.com/maps?q=from+A+to+B&output=kml

and then you view the data retrieved from that url (in kml format) and look at the placemark tags (run it through simplexml) each placemark tag will have a description child that will have a text description of the next step in the route from A to B. 然后你查看从该网址检索到的数据(以kml格式)并查看地标标记(通过simplexml运行)每个地标标记都有一个描述子标记,其中包含A路径中下一步的文本描述到B.

Also mentioned in the article is that by using this method you are bound by the google maps T&C which states 文章中还提到,通过使用此方法,您将受到谷歌地图T&C的约束

Also, you may not use Google Maps in a manner which gives you or any other person access to mass downloads or bulk feeds of numerical latitude and longitude coordinates. 此外,您不得以允许您或任何其他人访问大量下载或数字纬度和经度坐标批量输入的方式使用Google地图。

So you may want to keep that in mind. 所以你可能想要牢记这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM