I have been looking around and all that I could find are answers related to using google maps. What I want to do is get the information stored inside to "import" it to my database.
As far as I know, KMZ files are zip files of KML (like xml).
The KMZ that i want to process looks like this (when unzipped locally):
A KML file (doc.kml) with the following information:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>KmlFile</name>
<Placemark>
<description>
<![CDATA[<div style='border: 1px solid #aaa; font-size: 20px;'><span style='padding: 1em; display: inline-block;'><img src='files/tags_1470231.jpg' /></span></div>
<div style='background-color: #aaa; color: white; text-align: right; padding: 0.5em 0.5em 0 0;'>Posted: 2013/12/26</div>]]>
<![CDATA[<div style='border: 1px solid #aaa; font-size: 20px;'><span style='padding: 1em; display: inline-block;'>test
</span></div>
<div style='background-color: #aaa; color: white; text-align: right; padding: 0.5em 0.5em 0 0;'>Posted: 2013/12/26</div>]]>
<![CDATA[<div style='border: 1px solid #aaa; font-size: 20px;'><span style='padding: 1em; display: inline-block;'>cool pic</span></div>
<div style='background-color: #aaa; color: white; text-align: right; padding: 0.5em 0.5em 0 0;'>Posted: 2013/12/26</div>]]>
</description>
<visibility>0</visibility>
<Point>
<coordinates>135.753498,35.024914,0</coordinates>
</Point>
</Placemark>
<Placemark>
<description>
<![CDATA[<div style='border: 1px solid #aaa; font-size: 20px;'><span style='padding: 1em; display: inline-block;'><img src='files/tags_1470232.jpg' /></span></div>
<div style='background-color: #aaa; color: white; text-align: right; padding: 0.5em 0.5em 0 0;'>Posted: 2013/12/26</div>]]>
<![CDATA[<div style='border: 1px solid #aaa; font-size: 20px;'><span style='padding: 1em; display: inline-block;'>panda
</span></div>
<div style='background-color: #aaa; color: white; text-align: right; padding: 0.5em 0.5em 0 0;'>Posted: 2013/12/26</div>]]>
</description>
<visibility>0</visibility>
<Point>
<coordinates>135.753482,35.024868,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
And a folder called "files" with pictures inside it.
In theory I suppose I have to unzip this file in my server, read the doc.kml file, parse it to get the coordinates and the picture name for each of the elements, and then process this information.
What I am having trouble with is that I am not sure about how to unzip this file and process it in my server for each of the users that use the website.
Am i supposed to use a temporal location in my server? wont the files overwrite if several users do it at the same time? How do i reference each of the images once it has been unziped?
I am using a PHP site, and I plan on showing a preview with each of the images along with its coordinates for the uploaded KMZ file.
Any help would be greatly appreciated.
Here is some examples of code to uncompress the KMZ to the KML. This is quite easily done in php. Here is two php example:
From: http://dtbaker.net/web-development/how-to-convert-kmz-to-kml/ This worked fine on PHP 5.5.9, but I've found issues with this on PHP 5.4.35. I've solved this with the following code:
I got this from this post: Unzip a file with php From there you can pretty much handle a KML exactly like any other XML.
Hope that helps!