title: getting latitude longitude from address
body: <p>I am using the code below (entire html code posted) to return the latitude longitude from address but my problem is the way I am calling the function otherwise dealing with latitude longitude. The function returns null but if I display the contents inside the function (please search for "alert(results[0].geometry.location);// works fine here" I receive the right values,</p>
  
  <p>what is wrong with my javascript code that the getLatLng  function returns null?</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;Geocoding service&lt;/title&gt;
      &lt;style&gt;
        html, body, #map-canvas {
          height: 100%;
          margin: 0px;
          padding: 0px
        }
        #panel {
          position: absolute;
          top: 5px;
          left: 50%;
          margin-left: -180px;
          z-index: 5;
          background-color: #fff;
          padding: 5px;
          border: 1px solid #999;
        }
      &lt;/style&gt;
      &lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"&gt;&lt;/script&gt;
      &lt;script&gt;
  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
      zoom: 8,
      center: latlng
    }
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  }
  
  function codeAddress() {
    var address = document.getElementById('address').value;
    alert (getLatLng(address));
  }
  
  var getLatLng = function(stAddress){
  
    return geocoder.geocode( { 'address': stAddress}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        alert(results[0].geometry.location);// works fine here
        return results[0].geometry.location;
      } else {
        return -1;
      }
    });
  
  }
  
  
  google.maps.event.addDomListener(window, 'load', initialize);
  
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="panel"&gt;
        &lt;input id="address" type="textbox" value="Vancouver downtown"&gt;
        &lt;input type="button" value="Geocode" onclick="codeAddress()"&gt;
      &lt;/div&gt;
      &lt;div id="map-canvas"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>