title: Wait for callback in javascript
body: <p>I'm trying to create a function that returns a object with information of a callback:</p>
  
  <pre><code>var geoloc;
  
  var successful = function (position) {
      geoloc = {
          longitude: position.coords.longitude,
          latitude: position.coords.latitude
      };
  };
  
  var getLocation = function () {
      navigator.geolocation.getCurrentPosition(successful, function () {
          alert("fail");
      });
  
      return geoloc;
  };
  </code></pre>
  
  <p>How can I do this? The function <code>getLocation</code> return null value before <code>successful</code> is executed.</p>
  
  <p>Thanks!</p>