Question

I load an KML file into a google map object using the following code:

map = new GMap2(document.getElementById("map_canvas")); 
geoXml = new GGeoXml(kml);
GEvent.addListener(geoXml, "load", function() {
    geoXml.gotoDefaultViewport(map);
    // I would like to read the KML contents here
});
map.addOverlay(geoXml);
// ...

I would like to read the placemarks from the KML file and display them in a list. I know that the information I need is being transferred to the browser but I don't know how to access it.

Was it helpful?

Solution

You can't access it through the API, but the data is available in obfuscated properties inside GGeoXML object. Looking at it in Firebug, I found that information here: geoxml.$q.ia. Look at it yourself to see the properties you need (name, description, etc.).

OTHER TIPS

you can get the KML from the GGeoXML

have a variable in window

geoXml = new GGeoXml("http://mapgadgets.googlepages.com/cta.kml",
                         function(){
                              geoXml.getKml(
                                function(a){
                                  myKml = a;
                                  alert(myKml);
                                });} );

try it out here: http://code.google.com/apis/ajax/playground/?exp=maps#map_geoxml_kml

just change to one line , alternatively, if you don't want to use the callback of GGeoXML you can call getKml() in some other function after things have finished loading , provided your geoXml doesn't get wiped out

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top