The follwoing code loops over a json object to place marker on a google map. Which works fine.
function displayMarkers(data){
for(var i = 0; i < data.Lat.length; i++){
var point = new GLatLng(data.Lat[i],data.Lng[i]);
marker = new GMarker(point);
map.addOverlay(marker);
// here's the problem
GEvent.addListener(marker, "click", function(){
alert(data.Name[i]);
});
}
}
The problem is, every marker always responds with the last value of "i". I'm stuck trying to figure out a way to identify the marker that has been clicked to somehow get the right information from the data object.
I'm thinking about creating an array of markers at creation to loop through based on the markers location, but that feels really inefficient to me.
Any help, as always, greatly appreciated.