How to parse KML

5,327 views
Skip to first unread message

[A]JumP[S]

unread,
Jun 10, 2010, 6:45:22 AM6/10/10
to Google Maps JavaScript API v3
Well first of all, I'm very new to the Google Maps JavaScript API and
to the javascript itself. It quite fun playing around with it. But the
problem I face is about how to manipulate the KML stuff (marker from
KML). I search around the group and through other site for a while and
the most answer is mostly on the API2. I have come to the conclusion
of to parse the KML file myself.

As I see it's actually a xml file, so I just think it was going to be
easy like using the javascript to parse the xml file. Then I've create
the xml file (in which just change the KML file type to xml) and play
with it till I get a function to parse my file. By the way I use the
responseXML to parse the XML. But now the real problem is when I
switch the file to the original KML. It won't work.

Ok I use firebug to try debug it and I can see that it's because the
server response the content-type of KML as other type than "text/xml"
so I can't use that reponseXML but I can see that in responseText are
contain the stuff. So with my limited knowledge on javascript and web
setting stuff I'm stuck at this point. (I still have no idea on how to
parse the whole string of xml/KML and the motivation to do so yet)

So please can someone enlighten me of how to parse KML file that are
posting online. Can you please guide me to the right path or do I miss
some important method or others.

Thank you very much.

Rossko

unread,
Jun 10, 2010, 10:30:07 AM6/10/10
to Google Maps JavaScript API v3
> So please can someone enlighten me of how to parse KML file that are
> posting online. Can you please guide me to the right path or do I miss
> some important method or others.

Here's some useful info about XML fetching/parsing
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/fb7c7aff2d2859/c97a7ed7517e55c8

Here's a KML parser
http://econym.org.uk/gmap/egeoxml.htm
It's written for API v2, but you can adapt for v3

Don't forget there are cross-domain restrictions on accessing remote
XML (which includes any KML) from client side.

Here's a posting from someone who has been down this path already
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/a1f1b81dcdbbf17d/d287b00f52dc733e?lnk=gst&q=kml+parser#d287b00f52dc733e
Reply all
Reply to author
Forward
0 new messages