I am using the following function to geocode multiple addressees. The
addresses and address IDs are parsed and stored in arrays. All are
fine until the callback function is activated. I need to access the
address ID in the callback. However, since this is async call, the
looping is done by the time the callback is activated. Thus I always
get the last address and ID in the arrays. All the samples I found
pass latitudes and longitudes instead of addresses. Does anyone know
how to do this so that after each marker is added, the HTML in the
click event will have the correct address and ID? Thank you.
var map=null;
var geocoder=null;
function showAddressX(strAddresses, strAddressIds, strElementName) {
try
{
if (GBrowserIsCompatible())
{
var aryAddresses = strAddresses.split(";");
var aryAddressIds = strAddressIds.split(";");
map = new GMap2(document.getElementById(strElementName));
map.setMapType(G_SATELLITE_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
geocoder = new GClientGeocoder();
if(geocoder)
{
for (i=0; i<aryAddresses.length; i++)
{
var thisAddress = aryAddresses[i];
var thisAddressId = aryAddressIds[i];
geocoder.getLatLng(thisAddress,
function(point)
{
if (!point)
{
alert(aryAddresses[i] + " is not found");
}
else
{
map.setCenter(point, 12);
var marker = new GMarker(point);
var thisAddressHTML;
if (aryAddresses.length == 1)
thisAddressHTML = thisAddress;
else
thisAddressHTML = "<a
href='showProperty.aspx?show=" +
thisAddressId + "'>" + thisAddress + "<br/>" + i + "</a>";
GEvent.addListener(marker, "click",function()
{marker.openInfoWindowHtml(thisAddressHTML);})
map.addOverlay(marker);
}
} );
}
}
}
}
catch(e)
{
alert(e.name + '\n' + e.message);
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---