title: Google Maps v3 API Extend Bounds. Javascript How-To?
body: <pre><code>function initialize(){
  // Creating a map
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: new google.maps.LatLng(53.0123601276819, -2.44519164333635),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  
  var m = [];
  
  function addMarker(title, lat, lng) {
      m[m.length] = new google.maps.Marker({
          position: new google.maps.LatLng(lat, lng),
          map: map,
          title: title,  
          clickable: true,
          icon: 'http://domain.com/MVC/images/full.png' 
      });
  
  } 
  
  addMarker('Home', 53.0682143712504, -2.52150736731894);
  addMarker('Away', 53.0123601276819, -2.44519164333635);
  addMarker('Away', 59.0123601276819, -2.44519164333635);    
  
  // Create a LatLngBounds object
  var bounds = new google.maps.LatLngBounds(); 
  
  for (var i = 0; i &lt; m.length; i++) {
    // Insert code to add marker to map here
  
    // Extend the LatLngBound object
    bounds.extend(m[i]);
  
  }
  alert(m[0]);
  map.fitBounds(bounds);
    document.write(getBounds());   
  
  }
  </code></pre>
  
  <p>The above is my code. </p>
  
  <p>My intentions are to develop a map which shows numerous markers and pans the zoom such that all the markers fit on my screen.</p>
  
  <p>I am new to JS.</p>
  
  <p>My understanding is that </p>
  
  <pre><code>var m = [];
  </code></pre>
  
  <p>creates an empty array.</p>
  
  <p>Then everytime i call <code>addMarker()</code> the details get added to this array m</p>
  
  <p>At the top I set a default zoom and center point.</p>
  
  <p>I then add various markers.</p>
  
  <p>I then loop through each key in the m array and extend the bounds using the data from this.</p>
  
  <p>It is then my understanding that <code>map.fitBounds(bounds);</code> should redefine the zoom/center as applicable to fit all the markers.</p>
  
  <p>It does not.
  All my markers show, but the zoom/center is not auto adjusting as such, and I have no idea why.</p>
  
  <p>Any advice would be greatly appreciated.
  Thanks</p>