使用PHP解析KML文件 [英] Parse KML file with PHP
问题描述
是否可以使用simple_xml_load_file("*.kml")解析Google Maps * .kml文件?
Is there a way to parse google maps *.kml file with simple_xml_load_file("*.kml") ?
我需要在数据库中保存我的KML文件中注册的每个多边形的名称和坐标. 在我的PHP脚本中,simple_xml_load_file("*.kml")返回false,因此无法读取.
I need to save in my database name and coordinates of each polygons registered in my KML file. On my PHP script, simple_xml_load_file("*.kml") return false, so I can't read it.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<Schema>
...
</Schema>
<Style id="FEATURES">
...
</Style>
<Folder>
<Placemark>
<name>
name
</name>
<Polygon>
<LinearRing>
<coordinates>
coordinates
</coordinates>
</LinearRing>
</Polygon>
</Placemark>
<Placemark>
...
</Placemark>
</Folder>
</Document>
</kml>
每个地标"都需要名称"和坐标"值.
I need "name" and "coordinates" values for each "Placemark".
推荐答案
第一行:
<?xml version="1.0" encoding="UTF-8"?>
告诉PHP这是一个使用UTF-8编码的文档,但是您的错误表明它未编码为UTF-8.这是您使用文本编辑器创建的文档吗?如果是这样,通常可以使用编辑器将其保存在UTF-8中.或者,您可能可以使用PHP来检测编码并更改第一行.
Tells PHP that this is a document encoded in UTF-8, but your error says it is not encoded as UTF-8. Is this a doc you created with a text editor? If so, you can usually use your editor to save it out in UTF-8. Or you can probably use PHP to detect the encoding and change that first line.
这篇关于使用PHP解析KML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!