I am trying to get a KML from a URL to display in OpenLayers. However, it is a ground overlay so it cannot be displayed the standard way. I found this thread: [https://gis.stackexchange.com/questions/16816/does-openlayers-supports-kml-ground-overlays][1] [1]: https://gis.stackexchange.com/questions/16816/does-openlayers-supports-kml-ground-overlays

However, I am very lost as to how to parse this manually. I know I can make an AJA request and parse it, but don't think I can do that because of cross-domain issues.

So could someone guide me in the right direction to get a KML parsed directly from a URL?

1 Answer 1


If your openlayers application is already using a proxy, in my case i'm using OpenLayers.ProxyHost = "proxy/proxy.ashx?url="; You can use that to download your KML.

For example the url you would use in your ajax request is:


If you are not currently using a proxy file for these reasons you could make one or download one. It's basically just a handler. Depending on what platform/framework you're using on the backend... PHP, .NET, etc.

This way the browser does not request the KML. The request goes to your application server and your application server makes the request, then returns the response to the browser.

  • Thanks! I was thinking I would have to do that. But hoping there was a solution that would be easier since openlayers can normally grab a kml just fine from a url. This cross-domain ajax stuff is what causes the biggest headaches for me!
    – KyleK
    Commented Sep 12, 2012 at 15:15
  • yeah well, I would definitely try to do it without the proxy first, it might work and save yourself the trouble. But in case it does not, you can always use the proxy.
    – CaptDragon
    Commented Sep 12, 2012 at 15:20
  • Hey CaptDragon, this got me thinking about something. I was able to make my openlayers proxy work for a GetFeatureInfo request by just adding the url of the data into the cgi and making a call to the regular url. I have this:OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url="; at the top of my code. However, if I am not using the OpenLayers API to GET this kml, do I have to make the url:"/cgi-bin/proxy.cgi?url=KML_URL" in my GET? Sorry if this is confusing.
    – KyleK
    Commented Sep 12, 2012 at 16:08
  • Normally, yes, you still have do have to make the url /cgi-bin/proxy... even without OpenLayers because it would be the browser making the CB GET request and I'm pretty sure you'll get errors. But it never hearts to try first without it. If you are wondering why Google Maps API does not need it, it's because they send the KML back to their own servers first.
    – CaptDragon
    Commented Sep 12, 2012 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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