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

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

本文介绍了如何通过谷歌地图与PHP步行或驾驶距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前曾经使用过Google地图,但是在实现它时,我从来没有找到任何有关如何通过Javascript或PHP获得2个给定位置之间确切距离的文档。



它必须是地图上显示的完全相同的距离,而不是公式给出了从一个地理点到另一个地理点的直线距离。



2)它必须是PHP或Javascript



3)它必须是Google地图,而不是虚拟地球或类似的东西。



我想到的最好的事情是使用带变量的长URL向Google地图发送HTTP_GET请求,然后返回200代码加上网站的HTML。距离在那里,只需要过滤。

但是这是资源密集型和负载沉重的。



有人知道更好的方法吗?



编辑:提供了一种方式和警告。



要分解它,您可以使用Google地图来查询这样的URL

然后您查看从中检索到的数据url(以kml格式)并查看地标标记(通过simplexml运行它),每个地标标记都将有一个描述子元素,它将具有从A到B的路由中下一步的文本描述。



文中还提到,通过使用这种方法,您可以通过谷歌地图T& C进行绑定,该地图包含

所以你可能想保留记住。


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.

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.

2) It has to be either PHP or Javascript

3) It has to be Google maps, not virtual earth or anything similar.

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. 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.

解决方案

This posting gives a way and a warning.

To break it down you use google maps to query a URL like this

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.

Also mentioned in the article is that by using this method you are bound by the google maps T&C which states

So you may want to keep that in mind.

这篇关于如何通过谷歌地图与PHP步行或驾驶距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:04