title: Auto-center map with multiple markers in Google Maps API v3
body: <p>This is what I use to display a map with 3 pins/markers:</p>
  
  <pre><code>&lt;script&gt;
    function initialize() {
      var locations = [
        ['DESCRIPTION', 41.926979, 12.517385, 3],
        ['DESCRIPTION', 41.914873, 12.506486, 2],
        ['DESCRIPTION', 41.918574, 12.507201, 1]
      ];
  
      var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 15,
        center: new google.maps.LatLng(41.923, 12.513),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });
  
      var infowindow = new google.maps.InfoWindow();
  
      var marker, i;
  
      for (i = 0; i &lt; locations.length; i++) {
        marker = new google.maps.Marker({
          position: new google.maps.LatLng(locations[i][1], locations[i][2]),
          map: map
        });
  
        google.maps.event.addListener(marker, 'click', (function(marker, i) {
          return function() {
            infowindow.setContent(locations[i][0]);
            infowindow.open(map, marker);
          }
        })(marker, i));
      }
    }
  
    function loadScript() {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false&amp;' + 'callback=initialize';
      document.body.appendChild(script);
    }
  
    window.onload = loadScript;
  &lt;/script&gt;
  
  &lt;div id="map" style="width: 900px; height: 700px;"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>What I’m looking for is a way to avoid having to “manually” find the center of the map with <code>center: new google.maps.LatLng(41.923, 12.513)</code>. Is there a way to automatically have the map centered on the three coordinates?</p>