title: How to make map cover all markers in javascript?
body: <p>I have an issue with Google Map in javascript, I can not make all markers fit bounds. Only the first marker is visible.
  This is the error thrown in console:</p>
  
  <blockquote>
    <p>uncaught exception: InvalidValueError: not a LatLngBounds or LatLngBoundsLiteral: not an Object</p>
  </blockquote>
  
  <p>And this is the code I am using:</p>
  
  <pre><code>var map = new google.maps.Map(document.getElementById('map'), {
      center: {lat: parseFloat(lat), lng:parseFloat(lng)},
      zoom: 11
  });
  
  var bounds = new google.maps.LatLngBounds();
  
  for(var i = 0; i &lt; coordinates.length; i++){
  
      var coords = {lat: parseFloat(lat), lng:parseFloat(lng)}
  
      var marker = new google.maps.Marker({position: coords, map: map});
      var infowindow = new google.maps.InfoWindow();
  
      infowindow.setContent(lat);
      infowindow.open(map, marker);
  
      bounds.extend(marker.position);
  
  }
  
  map.setCenter(bounds.getCenter());
  map.fitBounds(bounds);  
  </code></pre>
  
  <p>I have 4 markers on the map, but map is zoomed and centered to the last one added, as seen in the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/0McEh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0McEh.png" alt="enter image description here"></a></p>
  
  <p>If I zoom out the map I can see all other markers, but fitbounds is not working to make all markers fit the bounds.</p>