title: Trouble displaying an array of markers on Google Maps v3
body: <p>I have written a short script to take an array of location objects (generated by PHP) and plot them on a Google Map.</p>
  
  <p>For the life of me, I cannot work out why the <code>addMarker()</code> loop breaks?</p>
  
  <p>An example of an array I am sending to <code>initializeMap()</code>:</p>
  
  <pre><code>[
      {
          date: '08/11/2011',
          venue: 'Notes',
          city: 'Newtown, NSW',
          ticket: 'http://noteslive.net.au/'
      }
  ]
  </code></pre>
  
  <p>And the code:</p>
  
  <pre><code>// Accepts an array of gigs  
  function initializeMap(gigs) {
  
  var markers = gigs;
  
  // Create geocoder
  var geocoder = new google.maps.Geocoder();
  
  // Create the map
  var map = new google.maps.Map(document.getElementById("gigpress-map"), {
      mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  
  // Create infowindow object
  var infowindow = new google.maps.InfoWindow({
      content: "holding..."
  });
  
  // Add markers to map
  for (index in markers) addMarker(markers[index]);
  
  function addMarker(data) {
      alert('bang');
      geocoder.geocode( { 'address': data.city}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
              var marker = new google.maps.Marker( {
                  position: results[0].geometry.location,
                  map: map,
                  title: data.venue
              });
          } else {
              alert("Geocode was not successful for the following reason: " + status);
          }
      });
  
      // Bind click event to each marker
      google.maps.event.addListener(marker, "click", function() {
          infowindow.open(map, this);
      });
  }
  
  // Zoom and center the map to fit the markers
  var bounds = new google.maps.LatLngBounds();
  
  for (index in markers) {
      var data = markers[index];
      geocoder.geocode( { 'address': data.city}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
              bounds.extend(new google.maps.LatLng(results[0].geometry.location));
          } else {
              alert("Geocode was not successful for the following reason: " + status);
          }
      }); 
  }
  
  map.fitBounds(bounds);
  }
  </code></pre>