1
A
回答
1
我为此写了代码,而不是英国地区的网格。
我必须使用DOMDocument::load()
来读取像XML这样的KML文件,这使您可以读取KML文件并获取其包含的经度和纬度点。请记住,虽然我不得不稍微更改KML以使其起作用。建立在谷歌地图自定义地图后,首先点击右键,复制谷歌地球链接 - 这将给像这样
http://maps.google.co.uk/maps/ms?ie=UTF8&hl=en&vps=1&jsv=314b&msa=0&output=nl
你应该改变输出kml
,请访问然后保存输出,我在这里省略了部分URL,因为不会放弃我的地图!
http://maps.google.co.uk/maps/ms?ie=UTF8&hl=en&vps=1&jsv=314b&msa=0&output=kml
然后我不得不删除<kml>
元素被删除以下行
<kml xmlns="http://earth.google.com/kml/2.2">
而且
</kml>
这将让你只用<Document>
元素其中包含的一点。然后使用DOMDocument读取它并遍历它以获取它包含的坐标。例如,您可以遍历地标和它们的坐标,创建一个polygin,然后与long相交。我用这个网站为多边形代码http://www.assemblysys.com/dataServices/php_pointinpolygon.php。正是在这个例子中一个实用程序类:
$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;
}
}
相关问题
- 1. 谷歌地图kml
- 2. 谷歌地图Javascript API与KML层?
- 3. 谷歌地图KML层
- 4. 通KML到谷歌地图
- 5. 动态kml谷歌地图
- 6. 谷歌地球KML
- 7. 谷歌地图呈现谷歌地球的KML反相
- 8. 谷歌地图引擎:export kml curl
- 9. 在谷歌地图api中切换kml
- 10. KML层Cursor CSS - 谷歌地图API v3
- 11. 通过谷歌地图API处理KML
- 12. iPhone谷歌地图KML搜索
- 13. 谷歌地图显示KML数据
- 14. 在谷歌地图上使用KML/KMZ
- 15. 谷歌地图不链接kml文件
- 16. 谷歌地图 - 加载KML覆盖
- 17. 谷歌地图API - KML负载(PHP)
- 18. 谷歌地图输出= kml坏了?
- 19. 谷歌地图 - 无法访问KML文件的KML层
- 20. 谷歌地图API - 添加KML图层到地图
- 21. 谷歌KML GX:DRAWORDER
- 22. 导入KML文件谷歌地图与API调用/请求
- 23. 谷歌地图API自动适合(fitBounds)与复杂的KML
- 24. jQuery和谷歌地图:如何AJAX它
- 25. 谷歌地图API,使用KML文件,地图是空白
- 26. 谷歌地图KML静态地图API路径
- 27. 谷歌地图API从KML图层反向地理编码
- 28. 懒惰/需求加载谷歌地图或谷歌地球插件KML?
- 29. 谷歌地图api v3和kml =缩放不起作用
- 30. Android - 如何使用Intent和KML打开谷歌地图?
我会尝试这一点,但我是一个菜鸟,超过这个东西一半是出于理解... – nomie 2011-02-10 15:57:05