views:

577

answers:

3

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.

+1  A: 

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.).

Mourner
Do you have any idea how stable the obfuscated properties are?
Fabian Jakobs
Unfortunately not...
Mourner
+1  A: 

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

Berwyn
A: 

berwyn your answer don't works at all ...

melusineChan