title: Google Maps batch reverse Geocoding Javascript
body: <p>So I know that Google API v3 prevents batch requests unless there is a 2 second delay - So I'm just trying to do a simple reverse Geocode using one request.</p>
  
  <p>You can see my array now only has one object (for now).</p>
  
  <p>The problem is that I'm returning an "undefined" value under the function "showAddress()". What's weird is that the address shows just fine on the google maps marker - but it won't let me return the value properly.</p>
  
  <p>Please ignore the fact I'm using extra functions when I don't need to - I will need these functions later for my full setup.</p>
  
  <p>Here's a JSBin --> <a href="http://jsbin.com/japudabu/1/edit?html,output" rel="nofollow">http://jsbin.com/japudabu/1/edit?html,output</a></p>
  
  <p>I think the problem is more here:</p>
  
  <pre><code>....
  
    infowindow.setContent(results[0].formatted_address);
    infowindow.open(map, marker);
    return results[0].formatted_address;
  
  ...
  </code></pre>
  
  <p>Here's the full setup:</p>
  
  <p>Javascript:</p>
  
  <pre><code>var geoArray = [
      {lat: 29.546604, lng: -98.407082}/*,
      {lat: 29.402672, lng: -98.392095},
      {lat: 29.769542, lng: -98.664527},
      {lat: 29.778432, lng: -98.464939},
      {lat: 29.78322, lng: -98.523551},
      {lat: 29.424455, lng: -98.403565},
      {lat: 29.342814, lng: -98.541336},
      {lat: 29.291922, lng: -98.434656},
      {lat: 29.354486, lng: -98.400621},
      {lat: 29.512927, lng: -98.439247},
      {lat: 29.386556, lng: -98.510591},
      {lat: 29.365009, lng: -98.427818},
      {lat: 29.363518, lng: -98.583277},
      {lat: 29.305123, lng: -98.429247},
      {lat: 29.673901, lng: -98.39694},
      {lat: 29.530874, lng: -98.446433}
      {lat: 29.374788, lng: -98.602789} */];
  
   var geocoder;
    var map;
    var infowindow = new google.maps.InfoWindow();
    var marker;
      function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(29.4814305,-98.5144044);
      var mapOptions = {
        zoom: 11,
        center: latlng,
        mapTypeId: 'roadmap'
      }
     // alert(mapOptions);
      map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
    }
  
  
  
  
    function codeLatLng(lat, lng) {
      var latlng = new google.maps.LatLng(lat, lng);
      geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (results[1]) {
            map.setZoom(11);
            marker = new google.maps.Marker({
                position: latlng,
                map: map
            });
            infowindow.setContent(results[0].formatted_address);
            infowindow.open(map, marker);
            return results[0].formatted_address;
          } else {
            alert('No results found');
          }
        } else {
          alert('Geocoder failed due to: ' + status);
        }
      });
    }
  
    function showAddress() {
      for (var i = 0; i &lt; geoArray.length; i++) {
          var x = 29.546604;
          var y = -98.407082;
          var myval = "address is: " + codeLatLng(x,y) + "&lt;br/&gt;";
          var thediv = document.getElementById('listme');
          thediv.innerHTML = thediv.innerHTML + myval;
      }
  
    }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;    
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Google Maps JavaScript API v3 Example: Reverse Geocoding&lt;/title&gt;
  &lt;link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet"&gt;
  &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"&gt;&lt;/script&gt;
  &lt;script&gt;
  &lt;body onload='initialize();'&gt;
    &lt;div&gt;
      &lt;input type="button" value="Reverse Geocode" onclick="showAddress()"&gt;
    &lt;/div&gt;
     &lt;div id="map_canvas" style="height: 80%; width:50%; border: 1px solid black;"&gt;&lt;/div&gt;
     &lt;div id='listme' style='position:fixed;bottom:10;left:10;'&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>