Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have found some info on here regarding opening a KML file (with groundoverlay) from a url in Openlayers. In order to open a KML with groundoverlay, it must first be parsed. However, after I GET, I am getting back a downloadable KML file. From the response in FireBug, I just see a bunch of giberish as the response! I want the KML(XML) so I can get the info out of it. Does anyone know exactly how to parse a downloadable kml from a url? Thanks!

Here is my code below. The url takes me to a kml that I can see in Google Earth. However, the response I get back is just a bunch of symbols according to Firebug, when I send as a GET. Any idea what I am doing wrong here to get the response in xml format?

    url: kmlURL
    callback: function(request) {
        {   alert(request.status + "::" + request.responseText);
            console.log(request.status + "::" + request.responseText);

    function kmlGroundOverlayParse(strKML)
    var NL = "\r\n";
    var parserXML = new OpenLayers.Format.XML();
    try {
    objKMLxml =;
    } catch(err) {

    var Msg="";
    var objLayerList = parserXML.getElementsByTagNameNS(objKMLxml, "*", "GroundOverlay");

    for(var i=0;i<objLayerList.length;i++)

    var derName = parserXML.getElementsByTagNameNS(objLayerList[i], "*", "name");

    var dasIcon = parserXML.getElementsByTagNameNS(objLayerList[i], "*", "Icon");
    var dieHREF = parserXML.getElementsByTagNameNS(dasIcon[0], "*", "href");

    var dieBox = parserXML.getElementsByTagNameNS(objLayerList[i], "*", "LatLonBox");
    var derNorden = parserXML.getElementsByTagNameNS(dieBox [0], "*", "north");
    var derWesten = parserXML.getElementsByTagNameNS(dieBox [0], "*", "west");
    var derSueden = parserXML.getElementsByTagNameNS(dieBox [0], "*", "south");
    var derOsten  = parserXML.getElementsByTagNameNS(dieBox [0], "*", "east");

    Msg += "name:" + derName[0].firstChild.nodeValue + ", ";
    Msg += "url:" + dieHREF[0].firstChild.nodeValue.substr(0,20) + ", ";
    Msg += "BOX:" + derWesten[0].firstChild.nodeValue + ", ";
    Msg += derSueden[0].firstChild.nodeValue + ", ";
    Msg += derOsten[0].firstChild.nodeValue + ", ";
    Msg += derNorden[0].firstChild.nodeValue + ", ";

    Msg += NL;

    var title = derName[0].firstChild.nodeValue;
    var url = dieHREF[0].firstChild.nodeValue;
    var projection = "EPSG:4326";

    var ptmin = [derWesten[0].firstChild.nodeValue,derSueden[0].firstChild.nodeValue];
    var ptmax = [derOsten[0].firstChild.nodeValue,derNorden[0].firstChild.nodeValue];

    var bounds = ptmin[0] + "," + ptmin[1] + "," + ptmax[0] + "," + ptmax[1];
    var size = "100,100"; //uninteressant, notwendig für addLayer??

    addKMLGroundOverlay(i, title, url, projection, bounds, size);

Msg += objLayerList.length;
parseMsg = Msg;


share|improve this question
Can you show us your code? That way it'd be easier to spot errors. – R.K. Sep 13 '12 at 6:25
GroundOverlays in Openlayers is not supported… - use LayerImage instead… – Mapperz Sep 13 '12 at 13:34
up vote 1 down vote accepted

if u use django or python on server side, u can use pykml(Python KML library) here.

dont forget to check out tutorials here about pykml.

from lxml import etree
from pykml.parser import Schema
from pykml.factory import KML_ElementMaker as KML
from pykml.factory import GX_ElementMaker as GX

i hope it helps you...

share|improve this answer
A coworker was able to make Grails specify the xml format I needed.. Guess I need to study up on server side a bit more! Thanks – KyleK Sep 14 '12 at 12:32

I've never tried to parse a KML, just a geojson file. You may want to convert the KML to a geojson file first. Plus json files are smaller and easier to parse. I got some help here with looping over the geojson file. I'd use the ogr2ogr tool to convert the file

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.