kml和Google Maps是否可能 [英] Is it possible with kml and google maps

查看:85
本文介绍了kml和Google Maps是否可能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道谷歌地图是否可行.我在带有kml文件的Google地图上创建了2个小网格.

I want to know if this is possible with google maps. I create a 2 small grids on google maps with kml file.

如何使用php找出我的地址是否列在网格1或2中.请寻求帮助.

How can I find out using php of if my address is listed in grid 1 or 2. Need help please.

推荐答案

我编写的代码正是针对英国地区的代码,而不是网格.

I wrote code for doing exactly this, but rather than grids, for areas of the UK.

我必须使用DOMDocument::load()读取XML之类的KML文件,这使您能够读取KML文件并获取其包含的经度和纬度点.请记住,尽管我必须稍微更改KML才能起作用.首先,在Google地图中构建自定义地图后,右键单击并复制Google Earth链接-这样会得到类似的结果

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 this

http://maps.google.co.uk/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=314b&msa=0&output=nl

您应该将输出更改为kml,访问然后保存输出,我在此省略了该URL的一部分,以免丢失我的地图!

You 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!

http://maps.google.co.uk/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=314b&msa=0&output=kml

然后我必须删除<kml>元素,然后删除以下几行

I then had to remove the <kml> element be removing the following lines

<kml xmlns="http://earth.google.com/kml/2.2">

还有

</kml>

这将只剩下包含该点的<Document>元素.然后,您可以使用DOMDocument读取此内容,并对其进行迭代以获取其包含的坐标.例如,您然后可以遍历地标及其坐标,创建polygin,然后将其与long相交.我将此网站用于多边形代码 http://www.assemblysys.com/dataServices/php_pointinpolygon.php .在此示例中,它是一个Util类:

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:

$dom = new DOMDocument();
$dom->load(APPLICATION_PATH . self::REGIONS_XML);   

$xpath = new DOMXpath($dom);
$result = $xpath->query("/Document/Placemark");

foreach($result as $i => $node)
{
    $name = $node->getElementsByTagName("name")->item(0)->nodeValue;

    $polygon = array();

    // For each coordinate
    foreach($node->getElementsByTagName("coordinates") as $j => $coord)
    {
        // Explode and parse coord to get meaningful data from it

        $coords = explode("\n" , $coord->nodeValue);

        foreach($coords as $k => $coordData)
        {
                if(strlen(trim($coordData)) < 1)
                    continue;

               $explodedData = explode("," , trim($coordData));

               // Add the coordinates to the polygon array for use in the 
               // polygon Util class. Note that the long and lat are 
               // switched here because the polygon class expected them 
               // a specific way around
               $polygon[] = $explodedData[1] . " " . $explodedData[0];
        }
    }

    // This is your address point        
    $point = $lat . " " . $lng;

    // Determine the location of $point in relation to $polygon
    $location = $pointLocation->pointInPolygon($point, $polygon);

    // $location will be a string, this is documented in the polygon link
    if($location == "inside" || $location == "boundary")
    {
          // If location is inside or on the boundary of this Placemark then break
          // and $name will contain the name of the Placemark 
          break;
    }
}

这篇关于kml和Google Maps是否可能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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