title: Trying to use Geocoder for several arrays of 100 addresses each one
body: <p>I use a javascript program that run Geocoder to get latitude and longitude for an array of addresses up to 100 and it run fine. However, if I want to process a list of addresses more than 100, I have to run this program several times, each time filling that array with 100 addresses or less, until I complete my list.</p>
  
  <p>I try to modify it, and split the array in several arrays, each one of 100 addresses and run Geocoder for each array. However, I only get executed the last array, maybe because the program run Geocoder in recursive mode. </p>
  
  <p>Is there a way to run geocode() for several arrays?</p>
  
  <p>In this example, I try to process a array of 150 addresses, so I will split it in two arrays, one of 100 and the other one of 50.</p>
  
  <p>Here I initialize variables:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var map = null;
  var geocoder = null;
  var addresses = null; /* array that will be used by geocode() function */
  var current_address = 0;
  var geocode_results = new Array();
  var markers = new Array();
  var infowindows = new Array();
  var timeouts = 0;
  var geocodeWait = 1000; //wait a second betweeen requests
  
  
  function initialize()
  {
      var mapOptions = {
          'zoom': 1,
          'center': new google.maps.LatLng(0.0,0.0),
          'mapTypeId': google.maps.MapTypeId.ROADMAP
      };
  
      map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  
      geocoder = new google.maps.Geocoder();
  
  }
  </code></pre>
  
  <p>This is the function that split array of addresses in 02 arrays and call geocode() function but it only processes last array</p>
  
  <pre><code>    function submitForm()
      {
              current_address = 0;
  
              /* this is the array that will contain list of 150 addressess */
              var temp_addresses = document.getElementById("addresses").value.split("\n");
  
              for(var x=0;x&lt;2;x++)  /*Here I try to split list in 2 arrays */
              {
  
                  current_address = 0;
  
                  var ini = x*100;
  
                  var fin = ini+99;
  
                  addresses = new Array(); /*array is reinitialized in each loop */
  
                  if  (fin &gt; temp_addresses.length) fin = temp_addresses.length;
  
                  for(var i=ini;i&lt;fin;i++)
                  {
                      if(temp_addresses[i].length&gt;1)addresses.push(temp_addresses[i]);
                     /* here 'addresses' array is filled to be used by 'geocode()' function */
                  }
  
                  geocode();  /* function is recursive but is only executed when 'x' get last value */
              }
      }
  </code></pre>
  
  <p>Here is the geocode() function:</p>
  
  <pre><code>function geocode() {
      if (current_address&lt;addresses.length &amp;&amp; geocoder) {
        document.getElementById("progress").innerHTML = "Geocoding " + (current_address+1) + " of " + addresses.length;
        geocoder.geocode( { 'address': addresses[current_address]},
        function(response, status) {
            geocode_results[current_address] = new Array();
            geocode_results[current_address]['status'] = status;
            if (!response || status != google.maps.GeocoderStatus.OK) {
              if(status == google.maps.GeocoderStatus.ZERO_RESULTS){
                  geocode_results[current_address]['lat'] = 0;
                  geocode_results[current_address]['lng'] = 0;
                  current_address++;
              } else {
                timeouts++;
                if(timeouts&gt;6){
                  alert("You have reached the limit of of requests that you can make to google from this IP address in one day, please wait 24 hours to continue");
                }
              }
            } else {
              timeouts = 0;
              var top_location = response[0];
              var lat = Math.round(top_location.geometry.location.lat() * 1000000)/1000000;
              var lng = Math.round(top_location.geometry.location.lng() * 1000000)/1000000;
              geocode_results[current_address]['lat'] = lat;
              geocode_results[current_address]['lng'] = lng;
              geocode_results[current_address]['l_type'] = top_location.geometry.location_type;
  
              var marker = markers[current_address] = new google.maps.Marker({
                    position: new google.maps.LatLng(lat,lng),
                    map: map,
                    title:"Line " + (current_address+1)
               });
  
              var infowindow = infowindows[current_address] = new google.maps.InfoWindow({
                  content: addresses[current_address] + "&lt;br/&gt;Latitude:" + lat + "&lt;br/&gt;Longitude:" + lng
              });
  
              google.maps.event.addListener(markers[current_address], 'click', function() {
                infowindow.open(map,marker);
              });
  
              current_address++;
            }
            var wait = geocodeWait+(timeouts * geocodeWait); //if it keeps timeing out increase wait time
            setTimeout("geocode()",wait);
        });
      } else {
        document.getElementById("progress").innerHTML = "finished";
        displayResults();
        document.getElementById("progress").innerHTML = "";
        fitAll();
      }
  }
  
  function displayResults()
  {
      var response = ""
      for(var i=0;i&lt;addresses.length;i++)
      {
          response += addresses[i] + "\t" + geocode_results[i]['lat'] + "\t" + geocode_results[i]['lng'] + "\n";
      }
  
      document.getElementById("resultados").value += response + "\n";
  
  }
  </code></pre>