How to get the KML data from a GGeoXml object

白昼怎懂夜的黑 提交于 2020-01-05 04:48:20

问题


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:


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




回答2:


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



来源:https://stackoverflow.com/questions/2013393/how-to-get-the-kml-data-from-a-ggeoxml-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!