Access KML placemarks in a Google Maps overlay via Javascript?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 20:06:55

Have you looked at GeoXML?

There does not seem to be an easy solution to this problem since Google doesn't provide the answer in the API. The only method I have found to get access to individual placemarks is to "capture" them when they are added to the map. In order to do this you have to set an 'addoverlay' listener on the map object. Something like this:

GEvent.addListener(map, 'addoverlay', function(o) {
    kmlmarkers.push(o);
}

However, I couldn't figure out a way to get the id of the placemark out of the marker object. Therefore the only way I was able to access specific placemarks was to loop through the array and match the markers with my data based upon the coordinates. It's not a real elegant solution but is was the only way that I was able to make it work.

You can figure that out by simply looking into the object as follows:

GEvent.addListener(map, 'addoverlay', function(obj)
{ if (!obj) {
        alert("Cannot describe a null object");
        return;
    }
    var str = "";

        for ( var prop in obj) {
            str += prop + " = " + obj[prop] + ",\n";
        }
        alert(str);
    });

That should help...

Look at Kml Update. You will need a placeark ID.

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