我正在使用KML文件来提取坐标并将它们插入到多维数组中。起初,我想只输出页面上的坐标 - 它似乎并不奏效PHP从KML文件获取坐标
这是到目前为止,我已经试过代码:
<?php
$url = "myKML.kml";
$contents = file_get_contents($url);
$xml = new SimpleXMLElement($contents);
$value = (string)$xml->Document->Placemark->Point->coordinates;
$coords = array();
foreach($value as $coord) {
$args = explode(",", $value);
$coords[] = array($args[0], $args[1], $args[2]);
}
print_r($coord);
?>
继承人的KML结构:
<Document>
<name>...</name>
<open>1</open>
<Snippet maxLines='0'></Snippet>
<description>.../description>
<Style >
<BalloonStyle>
<text>
...
</text>
</BalloonStyle>
</Style>
<Placemark >
<name>...</name>
<styleUrl>...</styleUrl>
<Snippet maxLines='0'></Snippet>
<ExtendedData>
<Data name='__title'>
<value>...</value>
</Data>
<Data name='__imgUrl'>
<value>...</value>
</Data>
<Data name='__data'>
<value>...</value>
</Data>
</ExtendedData>
<Point>
<coordinates>14.8184806108,56.8630456924,196.0000000000</coordinates>
</Point>
</Placemark>
谢谢你这么多的重播! ,但即使在“为每个”它只能给我一个协调...在我的XML我有很多动作......为什么是这样的?(我的意思是我有很多“地标”) – user2828251
我找到了一个解决方案,导致我到以下问题:http://stackoverflow.com/questions/19889686/php-with-xml-extract-2-nodes-to-one -array – user2828251
@ user2828251没有XPath为你工作?这正是你想要的。 –