title: Too much recursion error due to bounds.extend method
body: <p>I am trying to create bound and zoom to the my markers. But i have the error i mentioned at line:</p>
  
  <pre><code>bounds.extend(markers[i].position);
  </code></pre>
  
  <p>When i set the length of my markers.length in for loop then it gives <code>Too much recursion error</code><br>
  I have all the markers displayed but they are not zoomed and bounded and i also have the error which i just mentioned.</p>
  
  <p>My code to do this is:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;style&gt;
          #map-canvas {
              width: 1350px;
              height: 600px;
          }
      &lt;/style&gt;
      &lt;script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.js"&gt;&lt;/script&gt;
      &lt;script src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
      &lt;script&gt;
          function initialize() {
              //var markers = new Array();
              var markers = [];
              $.ajax({
                  type: 'GET',
                  url: './Content/TextFile/LongLat.txt',
                  //filereader\filereader\Content\TextFile\LongLat.txt
                  //  url: './distinctGimeiNo.txt',
                  dataType: 'text',
              }).success(function (data) {
                  var infowindow = new google.maps.InfoWindow();
  
                  var marker;
                  var s2 = data.replace(/^.*$/, " ").replace(/\r\n/g, " ");
                  var array = s2.split(/[ ]+/g);
                  var test = [].concat.apply([], array.map(function (array) { return array.split(/\s+/); }))
  
                  var col1 = [];
                  var col2 = [];
                  var col3 = [];
                  var j = 0;
                  // var currentLocation =
                  var mapOptions =
                      {
                          zoom: 2,
                          center: new google.maps.LatLng(73, 23),
                          mapTypeId: google.maps.MapTypeId.ROADMAP
                      }
                  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
                  for (var i = 0; i &lt;= test.length - 3; i = i + 3) {
                      col1[j] = test[i];
                      col2[j] = test[i + 1];
                      col3[j] = test[i + 2];
                      var myLatlng = new google.maps.LatLng(col3[j], col2[j]);
                      marker = new google.maps.Marker(
                         {
                             position: myLatlng,
                             map: map,
                             title: 'Hello World! ' + col1[j]
                         });
                      markers.push(marker);
                      console.log("test2");
                      j++;
                  }
                  function AutoCenter() {
                      var bounds = new google.maps.LatLngBounds();
                      for (var i = 0; i &lt; markers.length; i++) {
                          bounds.extend(markers[i].position);
                      }
                      map.fitBounds(bounds);
                  }
                  AutoCenter();
              })
          }
          google.maps.event.addDomListener(window, 'load', initialize);
          console.log("Check finished2");
      &lt;/script&gt;    
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="map-canvas"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Could someone please let me know the solution of the problem ?</p>