I have a list of arrays of location objects, and I use some of them to create a full address and then geocode. As soon as I get the status OK, I put the marker on the map. All of this works great. However, now I would also like to place an info window on each marker with a different property from the array list, LocationName. The code is here:
function placeMarkers(myObjList){ var geocoder = new google.maps.Geocoder(); for(var i=0; i<myObjList.length; i++){ var fullAddress = myObjList[i].Address + ", " + myObjList[i].City + ", " + myObjList[i].State + ", " + myObjList[i].Zip; var locationName = myObjList[i].LocationName; geocoder.geocode( { 'address': fullAddress}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { alert(locationName); var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location, clickable: true }); markers.push(marker); } else { alert("Geocode was not successful for the following reason: " + status); } }); } }
Warning - just to see what locationName is when I get this status OK. But when testing, this is always the same value. As soon as I can adapt this to reflect the correct value each time, then I have a code built to place information windows on the marker.
Any help would be greatly appreciated!
source share