title: Batch Geocoding
body: <p>I need to reverse geocode a list of thousands of latitude/longitude coordinates. I can do this for one set of coordinates no problem, but when it comes to many it will only do 5 at a time. I need to figure out how to do this in one step and time the loop so it will not get denied by google.</p>
  
  <p>I have been told elsewhere that I need to utilize callback functions but I am unsure how to do this.</p>
  
  <p>Here is some demo code</p>
  
  <pre><code>&lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
      &lt;script type="text/javascript" src="js/jquery-1.7.2.min.js" &gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;​​
      &lt;script type="text/javascript"&gt;                 
  
          var geocoder = new google.maps.Geocoder();
  
          var c = [];
          c[0]="43.5878,-79.6777";
          c[1]="49.2828,-123.1414";
          c[2]="49.2895,-123.127";
          c[3]="49.2784,-123.1364";
          c[4]="49.0327,-122.2529";
          c[5]="49.2696,-123.0587";
          c[6]="49.269,-122.9954";
          c[7]="49.235,-122.882";
          c[8]="49.1908,-122.7508";
          c[9]="49.085,-122.4111";
  
          var a = [];
  
          function codeLatLng(input, i) {
              var latlngStr = input.split(",", 2);
              var lat = parseFloat(latlngStr[0]);
              var lng = parseFloat(latlngStr[1]);
              var latlng = new google.maps.LatLng(lat, lng);
              geocoder.geocode({
                  'latLng' : latlng
              }, function(results, status) {  
                  a[i] = results[0].formatted_address;    
                  $("#test").append(a[i] + "&lt;br /&gt;"); 
              });
          }           
  
          function showmethemoney(){              
              for (var i=0; i &lt;= c.length - 1; i++) {                 
                  $("#test").append(i + ") " + c[i] + "&lt;br/&gt;");   
                  codeLatLng(c[i], i);                                    
              };  
          }
     &lt;/script&gt;   
  &lt;/head&gt;
  &lt;body&gt;        
      &lt;div id="test"&gt;&lt;/div&gt;
  
      &lt;br /&gt;
      &lt;button onclick="showmethemoney();"&gt;Show me the money!&lt;/button&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I need my results to be inline with their coordinates. </p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Thanks.</p>
  
  <p>Edit:</p>
  
  <p>Getting a little bit further:</p>
  
  <pre><code>        var geocoder = new google.maps.Geocoder();
  
          var c = [];
          c[0]="43.5878,-79.6777";
          c[1]="49.2828,-123.1414";
          c[2]="49.2895,-123.127";
          c[3]="49.2784,-123.1364";
          c[4]="49.0327,-122.2529";
          c[5]="49.2696,-123.0587";
          c[6]="49.269,-122.9954";
          c[7]="49.235,-122.882";
          c[8]="49.1908,-122.7508";
          c[9]="49.085,-122.4111";
  
          var a = [];
  
          function codeLatLng(input, i) {
              var latlngStr = input.split(",", 2);
              var lat = parseFloat(latlngStr[0]);
              var lng = parseFloat(latlngStr[1]);
              var latlng = new google.maps.LatLng(lat, lng);
              geocoder.geocode({
                  'latLng' : latlng
              }, function(results, status) {
                  //$("#test").append(results[0].formatted_address + "&lt;br /&gt;");       
                  a[i] = results[0].formatted_address;    
                  $("#test").append(a[i] + "&lt;br /&gt;"); 
              });
          }           
          var i = 0;
          function showmethemoney(start, end) {
  
              for (i = start; i &lt;= c.length - 1 &amp;&amp; i &lt; end; i++) {
                  $("#test").append(i + ") " + c[i] + " - ");
                  codeLatLng(c[i], i);
              }
              if( i &gt;= c.length - 1){
                  return;
              }
              setTimeout(function(){
                  showmethemoney(i, i+1);
              }, 1500);
          }
  
     &lt;/script&gt;   
  &lt;/head&gt;
  &lt;body&gt;        
      &lt;div id="test"&gt;&lt;/div&gt;
  
      &lt;br /&gt;
      &lt;button onclick="showmethemoney(0, 1);"&gt;Show me the money!&lt;/button&gt;
  &lt;/body&gt;
  </code></pre>