title: Javascript waiting for google geocoder
body: <p>I have this code and problem is that it alerts "undefined". How can I make <code>alert (add);</code> wait for geocoder? (I don't want to use <code>alert (add);</code> in <code>function codeAdd</code>)
          
      
      
       
      
      </p>
  
  <pre><code>&lt;script&gt;
  
  function codeAdd(address){
  var geocoder = new google.maps.Geocoder();
  var address = "new york";
  
  geocoder.geocode( { 'address': address}, function(results, status) {
  
    if (status == google.maps.GeocoderStatus.OK) {
      var latitude = results[0].geometry.location.lat();
      var longitude = results[0].geometry.location.lng();
      return latitude;
    } 
  }); }
  
  var add = codeAdd("new york");
  alert (add);
  
  
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>