getMetadata/KmlLayerMetadata

770 views
Skip to first unread message

this.me

unread,
Jun 4, 2010, 9:15:57 PM6/4/10
to Google Maps JavaScript API v3
Good evening,

I am having the hardest time interpreting the API reference for
getMetadata.

Assuming my KmlLayer object is kmllayer, then:

kmllayer.getUrl() returns the Url, kmllayer.setMap(map) renders the
overlay on the map but kmllayer.getMetadata() returns undefined.

kmllayer.getMetadata.name returns blank,
kmllayer.getMetadata.description returns undefined.

Can anyone provide an example of the proper syntax for using
getMetadata?

Thanks much.

Also, there is an error in the example code under the KML Feature Data
at:
http://code.google.com/apis/maps/documentation/javascript/overlays.html#KMLLayers

The example reads:
google.maps.event.addListener(ctaLayer, 'click',
function(kmlEvent) ...

Unfortunately, ctaLayer is undefined. The actual layer should be
nylayer, as per the original declaration.

Chad Killingsworth

unread,
Jun 5, 2010, 8:01:40 PM6/5/10
to Google Maps JavaScript API v3
With my own testing, it appears that getMetadata only returns an
object after the layer has finished rendering. Intuitively this makes
sense. However the problem is there isn't an event directly designed
to tell you when this is ready. I was able to use the tilesloaded
event on the map to accomplish the same thing though.

map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
ctaLayer = new google.maps.KmlLayer('http://gmaps-
samples.googlecode.com/svn/trunk/ggeoxml/cta.kml');
google.maps.event.addListenerOnce(map, 'tilesloaded', function()
{ console.log(ctaLayer.getMetadata()) });
ctaLayer.setMap(map);

Chad Killingsworth

On Jun 4, 8:15 pm, "this.me" <fl0atprecis...@gmail.com> wrote:
> Good evening,
>
> I am having the hardest time interpreting the API reference for
> getMetadata.
>
> Assuming my KmlLayer object is kmllayer, then:
>
> kmllayer.getUrl() returns the Url, kmllayer.setMap(map) renders the
> overlay on the map but kmllayer.getMetadata() returns undefined.
>
> kmllayer.getMetadata.name returns blank,
> kmllayer.getMetadata.description returns undefined.
>
> Can anyone provide an example of the proper syntax for using
> getMetadata?
>
> Thanks much.
>
> Also, there is an error in the example code under the KML Feature Data
> at:http://code.google.com/apis/maps/documentation/javascript/overlays.ht...

this.me

unread,
Jun 6, 2010, 10:52:37 PM6/6/10
to Google Maps JavaScript API v3
Chad, thanks, that worked great.

My only change was from 'tilesloaded' for the map to
"metadata_changed" for the layer, because of the API reference.

For some reason, I was unable to store getMetadata().name into a
variable, but if I call a function, sending getMetadata().name and
then storing the variable, it works. Guess that was my problem, but
you pointed me in the right direction.

Thanks much!
Reply all
Reply to author
Forward
0 new messages