I had email from eszpee off list and with his help solved my problem.
Yay! Thanks eszpee
And for anyone else stuck on this, the problem with eszpee's code
example above is that he is re-declaring the external function
variable i as a parameter in the new geocode callback function:
function convert_addresses() {
var addresses = document.forms.input.addresses.value.split('\n');
var i;
for (i = 0; i < addresses.length; i += 1) {
var actual_address = addresses[i];
geocoder.geocode( { 'address': actual_address}, function(results,
status, i) {
if (status == google.maps.GeocoderStatus.OK) {
alert(i+': '+results[0].formatted_address
+'\n'+results[0].geometry.location.toString()
+'\n'+results[0].geometry.location_type);
} else {
alert(i+': '+"Geocode was not successful for the following
reason: " + status);
}
});
}
}
The solution is to avoid the additional function argument. Without it
closure works as it should do with the internal function definition
picking up the external function variable i:
function convert_addresses() {
var addresses = document.forms.input.addresses.value.split('\n');
var i;
for (i = 0; i < addresses.length; i += 1) {
var actual_address = addresses[i];
geocoder.geocode( { 'address': actual_address}, function(results,
status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(i+': '+results[0].formatted_address
+'\n'+results[0].geometry.location.toString()
+'\n'+results[0].geometry.location_type);
} else {
alert(i+': '+"Geocode was not successful for the following
reason: " + status);
}
});
}
}
As I understand it, with the additional argument i, i gets set to
"undefined" when the callback function is called and is passed only
the first two arguments ...
Hope that is helpful for others.
CHEERS> SAM