This is the part of my code I am having troubles with, in this example
there are 2 addresses in the addressArray.
function setMarkers() {
var marker = new Array();
var numAddresses = addressArray.length;
var i;
for (i=0;i<numAddresses;i++) {
------> //IF I "alert(i)" HERE I GET THE
CORRECT RESPONSE (0,1,2 etc.) <-------
geocoder.getLocations(addressArray[i], function
(result) {
------>//IF I "alert(i)" HERE I GET "2"
EVERYTIME <------
place = result.Placemark[0];
point = new
GLatLng(place.Point.coordinates
[1],place.Point.coordinates[0]);
marker[i] = new GMarker(point);
map.addOverlay(marker[i]);
updateMarker(marker[i], i);
}
);
}
}
How do I get the callback function to get the correct value of "i"?
Why is it "2" everytime I alert it? Obviously "i" is in the same scope
because "i" is defined. The markers are added in the correct spots,
but when I call the update marker function to add infowindows to the
markers on click, the addresses dont show up in the info window
because it is passing 2 as the value of "i" and there is not
addressArray[2], since there is only 2 total addresses.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---