title: How do I return a longitude and latitude from Google Maps JavaScript geocoder?
body: <p>When I use the code below its alerting a blank value? why is that?</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;body onload="initialize()"&gt;
   &lt;div id="map_canvas" style="width: 320px; height: 480px;"&gt;&lt;/div&gt;
    &lt;div&gt;
      &lt;input id="address" type="textbox" value="Sydney, NSW"&gt;
      &lt;input type="button" value="Encode" onclick="display()"&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>JavaScript</p>
  
  <pre><code>var geocoder;
  var map;
  
  
    function initialize() {
      geocoder = new google.maps.Geocoder();
      var latlng = new google.maps.LatLng(-34.397, 150.644);
      var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }
  
    function codeAddress() {
      var address = document.getElementById("address").value;
      var loc=[];
  
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          loc[0]=results[0].geometry.location.lat();
          loc[1]=results[0].geometry.location.lng();
  
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });
  
      return loc;
    }
  
    function display(){
       var long_lat=codeAddress();
      alert(long_lat);
    }
  </code></pre>