title: How do I return a variable from Google Maps JavaScript geocoder callback?
body: <p>I am working with the google maps API and whenever I return the variable to the initialize function from the codeLatLng function it claims undefined. If I print the variable from the codeLatLng it shows up fine. </p>
  
  <pre><code>  var geocoder;
    function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(40.730885,-73.997383);
      var addr = codeLatLng();
      document.write(addr);
  
    }
  
    function codeLatLng() {
      var latlng = new google.maps.LatLng(40.730885,-73.997383);
      if (geocoder) {
        geocoder.geocode({'latLng': latlng}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
                  return results[1].formatted_address;
            } else {
              alert("No results found");
            }
          } else {
            alert("Geocoder failed due to: " + status);
          }
        });
      }
    }
  </code></pre>
  
  <p>prints out undefined</p>
  
  <p>If I do:</p>
  
  <pre><code>  var geocoder;
    function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(40.730885,-73.997383);
      codeLatLng();
  
  
    }
  
    function codeLatLng() {
      var latlng = new google.maps.LatLng(40.730885,-73.997383);
      if (geocoder) {
        geocoder.geocode({'latLng': latlng}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
                  document.write(results[1].formatted_address);
            } else {
              alert("No results found");
            }
          } else {
            alert("Geocoder failed due to: " + status);
          }
        });
      }
    }
  </code></pre>
  
  <p>prints out New York, NY 10012, USA</p>