You can fix this issue like this:
for (var i = 0; i < addresses.length; i++) { (function () { /* ################################################## */ var address = addresses[i]; var lat_lang = new google.maps.LatLng(address.latitude, address.longitude); var marker = new google.maps.Marker({ position: lat_lang, map: map }); markers[markers.length] = marker; var infowindow = new google.maps.InfoWindow({ content: address.address }); infowindows[infowindows.length] = infowindow; google.maps.event.addListener(marker, 'click', function() { close_infowindows(); infowindow.open(map, marker); }); })(); /* ################################################## */ }
By adding the lines marked with /* ################################################## */ in the middle of your loop…
I hope this helps someone

I'm a programmer at 
Thanks!!!
Comment
Yeah!!
Thanks a lot!!!!
Comment
HOW DOES IT WORK!??!
THANKS!
Comment
It helped me a lot, but I have no idea, why it works in this way.
Comment
Dear, Thank you very much. It really helped me. God bless you….
Comment
OMG! It work! Thank you!!!
p.s. How does it work???
Comment
Perfect!
Comment
Thanks. It is that I need.
Comment
It did help me A LOT. (more than my TAs @ Harvard)
Thanks.
Comment
You are a genius and my friend. I too would love to know why this works
Comment
You can get some ideas about how this works from this post:
http://stackoverflow.com/questions/2421911/what-is-the-purpose-of-wrapping-whole-javascript-files-in-anonymous-functions-lik/2421949#2421949
Comment
thanks a lot! that’s great!
Comment
THANKS THANKS AND THANKS!!! YOU’RE THE BEST! YOU DON’T HAVE A IDEA HOW LONG I WAS SEARCHING FOR A SOLUTION OF MY PROBLEM!!!
Greatings from Germany
Comment