开发者

How to get the KML data from a GGeoXml object

开发者 https://www.devze.com 2022-12-16 01:54 出处:网络
I load an KML file into a google map object using the following code: map = new GMap2(document.getElementById(\"map_canvas\"));

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);
//开发者_StackOverflow中文版 ...

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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消