Hi.  Forgive me.  I know this is a JavaScript challenge and not a
Google Maps challenge.   I have Google Maps v3 and I have arrays that
loop for marker locations and for InfoWindows. The marker locations
work out just fine. But for the life of me I can't sort out the
JavaScript loop for the InfoWindows.  Right now my InfoWindows all
return the last element in the array.  I expect this has something to
do either with JS global variables OR JS closure challenges.  If a JS
whiz can take a look and help me with a solution, I could not be more
grateful.  Thank you.  Here's the code:

function initialize() {
var map_center = new google.maps.LatLng(0,0);
var myContent = new Array('Desc1', 'Desc2', 'Desc3', 'Desc4');
var myLocations = new Array();
var myResNames = new Array('Amber Lea Place', 'Charlotte Villa',
'Tranquility Place', 'Versa Care Retirement Community');
myLocations = [
new google.maps.LatLng(43.1567732,-80.2740597),
new google.maps.LatLng(43.1404795,-80.2616147),
new google.maps.LatLng(43.1789781,-80.3246834),
new google.maps.LatLng(43.1793855,-80.2489434)
];
var myOptions = {
zoom: 12,
center: map_center,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var bounds = new google.maps.LatLngBounds();
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);

var info = new google.maps.InfoWindow();

for(var i=0;i<myLocations.length;i++)
{
        markers[i] = new google.maps.Marker({
                position: myLocations[i],
                map: map,
                title: myResNames[i]
                });
                var ContentID = myContent[i];

google.maps.event.addListener(markers[i], 'click',
function() {
         info.setContent(ContentID);
         info.open(map, this);
});
bounds.extend(myLocations[i]);
map.fitBounds(bounds);
}


}
</script>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

Reply via email to