Reputation: 2001
I need to get marker icon url on click, I saw on google maps documentation that there is function getIcon() but don't know where to call it.
google.maps.event.addListener(layer, 'click', function (kmlEvent) {
alert(kmlEvent.getIcon());//Object #<Object> has no method 'getIcon'
showInContentWindow(map, kmlEvent);
});
Update:
var myOptions = {
zoom: 8,
center: null,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("kmlMapCanvas"), myOptions);
var layer = new google.maps.KmlLayer(
'https://maps.google.co.uk/maps/ms?msid=207817312541605896974.0004cdbf70e9c541de0ac&msa=0&ll=51.499019,-0.58382&spn=0.070103,0.209255&output=kml',
{
suppressInfoWindows: true,
map: map
});
google.maps.event.addListener(layer, 'click', function (kmlEvent) {
alert(kmlEvent.getIcon());//Object #<Object> has no method
showInContentWindow(map, kmlEvent);
});
where I am losing connection with native marker....
Upvotes: 0
Views: 11938
Reputation: 161334
You can't access the icon if you render your KML using KmlLayer. If you use a third party parser, like geoxml3 or geoxml-v3, which renders the KML using native Google Maps API v3 markers, you can access the icon, using the getIcon() method on the marker.
Your KML displayed with geoxml3
The urls of the icons are:
geoXmlDoc.placemarks[0].marker.getIcon().url
geoXmlDoc.placemarks[1].marker.getIcon().url
geoXmlDoc.placemarks[2].marker.getIcon().url
This works on that page (in the address bar, at least in IE):
javascript:alert(geoXmlDoc.placemarks[0].marker.getIcon().url);
Upvotes: 4
Reputation: 6232
make sure kmlEvent
is your marker, because getIcon()
is a google.maps.Marker method
based on your comment
how can I load/get native marker
this is how you add a marker to the map
var marker = new google.maps.Marker({
position: userLatLngvariable,
title: 'Your title here',
draggable: true,
map: map
});
see a working example here: http://jsfiddle.net/RASG/vA4eQ/
(click the "add marker" button)
Upvotes: 1
Reputation: 117324
getIcon()
is a method of google.maps.Marker
. Placemarks(I guess that's what you click on), are rendered as markers, but are not native markers, so there is no method getIcon() you can use here.
There is no option inside the Maps-API to retrieve information about the rendered marker(Placemark).
Upvotes: 1