可以用kml和谷歌地图吗
我想知道谷歌地图是否可以实现这一点。我使用 kml 文件在谷歌地图上创建了 2 个小网格。
我如何使用 php 找出我的地址是否列在网格 1 或 2 中。请需要帮助。
I want to know if this is possible with google maps. I create a 2 small grids on google maps with kml file.
How can I find out using php of if my address is listed in grid 1 or 2. Need help please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我为英国的地区编写了专门执行此操作的代码,但不是网格。
我必须使用 DOMDocument::load() 像 XML 一样读取 KML 文件,这使您能够读取 KML 文件并获取它包含的经度和纬度点。但请记住,我必须稍微更改 KML 才能使其正常工作。首先,在 Google 地图中构建自定义地图后,右键单击并复制 Google 地球链接 - 这将给出类似这样的内容
您应该将输出更改为
kml
,访问然后保存输出,我在这里省略了该 URL 的一部分,以免泄露我的地图!然后我不得不删除
元素将删除以下行,
这将只留下包含该点的
元素。然后,您可以使用 DOMDocument 读取此内容并迭代它以获取它包含的坐标。例如,您可以迭代地标及其坐标,创建一个多边形,然后将其与长形相交。我使用这个网站的多边形代码 http://www. assemblysys.com/dataServices/php_pointinpolygon.php 。在本例中它是一个 Util 类:I wrote code for doing exactly this, but rather than grids, for areas of the UK.
I had to read the KML file like XML using
DOMDocument::load()
, this enables you to read the KML file and get the longitude and latitude points it contains. Bear in mind though that I had to change the KML slightly for this to work. Firstly after building your custom map in Google Maps right click and copy the Google Earth link - this will give something like thisYou should change the output to
kml
, visit then save the output, I have ommitted part of this URL here as not to give away my map!I then had to remove the
<kml>
element be removing the following linesAnd
This will leave you with just the
<Document>
element which contains the point. You then read this using DOMDocument and iterate over it to get the coordinates it contains. For example you can then iterate over the Placemarks and their coordinates, creating a polygin and then intersecting that with the long. I used this site for the polygon code http://www.assemblysys.com/dataServices/php_pointinpolygon.php . It is a Util class in this example: