title: Google Maps Geocoding and ploting several locations
body: <p>I am trying to implement a script that will geocode and plot all the locations of an array into a map. I am stack because I cannot get the map to fit all the markers added in the screen. I lost many hours trying several methods and this what I came up to:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt; 
  &lt;head&gt; 
    &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt; 
    &lt;title&gt;Google Maps Multiple Markers&lt;/title&gt;
    &lt;script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'&gt;&lt;/script&gt;
    &lt;script&gt;
  
      var geocoder;
      var map;
      var markersArray = [];
      var bounds;
  
      //plot initial point using geocode instead of coordinates (works just fine)
      function initialize() {
          geocoder = new google.maps.Geocoder();
          bounds = new google.maps.LatLngBounds ();
          latlang = geocoder.geocode( { 'address': '5th Avenus New Yort'}, function(results, status) { 
              if (status == google.maps.GeocoderStatus.OK) {
  
                  //map.setCenter(results[0].geometry.location);
                  marker = new google.maps.Marker({
                      map: map,
                      position: results[0].geometry.location
                  });
  
                  markersArray.push(marker);
              }
              else{
                  alert("Geocode was not successful for the following reason: " + status);
              }
          });
          var myOptions = {
              center: latlang, 
              zoom: 2, 
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              navigationControlOptions: {
                  style: google.maps.NavigationControlStyle.SMALL
              }
          };
          map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  
  
          plotMarkers();
        }
  
  
          var locationsArray = [
              ['Google Official','1600 Amphitheatre Parkway, Mountain View, USA'],
              ['Google 1','112 S. Main St., Ann Arbor, USA'], 
              ['Google 2','10 10th Street NE, Suite 600 USA']
          ];
  
          function plotMarkers(){
              for(var i = 0; i &lt; locationsArray.length; i++){
                  console.log(locationsArray[i][1]);
                  //codeAddresses(locationsArray[i]);
              }
  
              //map.fitBounds (bounds);
          }
  
          function codeAddresses(address){
              geocoder.geocode( { 'address': address}, function(results, status) { 
                  if (status == google.maps.GeocoderStatus.OK) {
  
                          //map.setCenter(results[0].geometry.location);
                          marker = new google.maps.Marker({
                              map: map,
                              position: results[0].geometry.location
                          });
  
  
                          bounds.extend (new google.maps.LatLng (results[0].geometry.location.ib,results[0].geometry.location.hb));
                          //console.log(bounds);
  
                      markersArray.push(marker); 
                  }
                  else{
                      alert("Geocode was not successful for the following reason: " + status);
                  }
              });
          }
  
          google.maps.event.addDomListener(window, 'load', initialize);
    &lt;/script&gt;
  &lt;/head&gt; 
  &lt;body&gt;
    &lt;div id="map_canvas" style="width: 100%; height: 700px;"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Can somebody give me a hand on this because it seems that I am going to stick with this version forever.</p>
  
  <p>I have the following to goals:
  1. Bound the displayed map so that all markers placed in the map will be displayed.
  2. Add infoWindow with the name of the location. </p>
  
  <p>I would appreaciate any help!</p>
  
  <p>Regards to all of you,
  Nick</p>