Hi, am new in using the Google Maps API. This might be a minor
question but i just cant seem to figure it out.
i have a for loop that creates markers dynamically. on creation of
each marker, an "onclick" event is added. the event is as simple as
generating an alert with the marker's id as reflected in the database.
The problem is all the markers seem to take the id of the very last
marker in the loop. ie. onclick, the id generated is the same for all
the markers.
here's the code:
GDownloadUrl("retrieve_markers.php", function(data) {
var markersXml = GXml.parse(data);
var points = markersXml.documentElement.getElementsByTagName
("points");
var mymarkers = points.length;
for(var i=1; i<=mymarkers; i++)
{
var markerId = parseFloat(position[i].getAttribute("markerId"));
var latitude= parseFloat(position[i].getAttribute("lat"));
var longitude = parseFloat(position[i].getAttribute("lon"));
marker = new GMarker (new GLatLng(latitude, longitude), customIcons
["green"]);
map.addOverlay(marker);
GEvent.addListener( marker, "click", function() {
onClickHandler(markerId);//this function simply alerts the value of
'markerId'
});
}
i'll really appreciate your help. thank you in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---