Hi,

I add Google Maps Markers on a map, and want to bind a click event on
each of them: I add the markers on the map in a loop, so the binding
of the event is done in the loop for each marker.
But it seems that when I click on the markers on the map, the callback
function will execute the same instructions for all the markers: the
instructions that have been set for the last marker.
It seems to be a problem with the references ...
Here is code to make it all clear:

for(key in data) {
      [...]
      var pointDep = new GLatLng(data[key][2], data[key][1]);
      var markerDep = new GMarker(pointDep, icon);
      alert(data[key][6]);
      GEvent.addListener(markerDep, "click", function() {
            alert(data[key][6]);
      });
      [...]
}

When loading the page, the first alert will for example display:
A
B
C
D

And the alert inside the event listener will only display D when I
click on any marker. I was expecting respectively to get alerts of A,
B, C and D.

The same has been done in this paragraph but it works:
http://code.google.com/intl/fr/apis/maps/documentation/events.html#Event_Closures
They also add the markers via a loop, so I can't understand why my
code doesn't work and their does. Some difference somewhere ...

Thank you for any help!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to