我正在使用 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>