I have the following scripts that create markers on a Google map.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function ShowAddresses(Addresses, PropertyIDs) {
var myOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var bounds = new google.maps.LatLngBounds();
var myArray = Addresses.split(";");
var IDs = PropertyIDs.split(";");
for (var i = 0; i < myArray.length; i++) {
var address = myArray[i];
var propertyID = IDs[i];
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
alert(propertyID);
var marker = new google.maps.Marker({
position: results[0].geometry.location,
title: results[0].formatted_address + "(" + propertyID + ")",
animation: google.maps.Animation.DROP,
url: "PropertyDetails.aspx?prop_i=" + propertyID,
map: map
});
google.maps.event.addListener(marker, "click", function () {
window.location = marker.url;
});
bounds.extend(results[0].geometry.location);
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
</script>
Select all Open in new window
I pass in delimited lists for address and property ID (these come from the database behind). I want to use the property id to reference the local page when clicked.
My issue is that the 'propertyID' used in the 'geocoder.geocode' is always the last item in the list. What is the best way to get the current propertyID to be used?
Open in new window