Search code examples
javascriptxmlgoogle-mapskmlgeo

How to get the KML from the external url with geoXML3?


Is it possible somehow to get the KML from the source out of the same domain. I mean to avoid the "Same origin policy for Javascript" somehow? (caching on our server is not the case since the application is intended to work with external sources)

The code below is what we're trying to accomplish (it give the error in case of external kml source).

<script type="text/javascript">
    var myParser = new geoXML3.parser({afterParse: useTheData});
    myParser.parse('http://api.flickr.com/services/feeds/geo/?g=94823070@N00&lang=en-us&format=kml');

    function useTheData(doc) {
        // out callback
    };
</script>

What is the reason to ask if there is that policy? Since google.maps.KmlLayer make this kind of job. Don't know how or I miss something. Really need it with geoxml3 and to understand what is under the curtain!


Solution

  • If you are accessing a publicly available KML you can simply load it as a standard google overlay

    var ctaLayer = new google.maps.KmlLayer('http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml');
    ctaLayer.setMap(map);
    

    Otherwise if you really need to use geoxml you will need to proxy the kml file (use a server side script that will load the file for you).