title: Loading Coordinates in a Factory Asynchronously in Angular
body: <p>My call to the factory returns too quickly in my map controller. I am trying to set the centre of the map however since the call to geo returns undefined it never sets centre. However the coordinates are grabbed in the geo factory. They are just too late.</p>
  
  <p>I thought the point of .then() was to wait for the date to be returned. So, how do I force my app to wait?</p>
  
  <p>My factory is:</p>
  
  <pre><code>angular.module('comhubApp')
  .factory('geo', function ($q) {
  
  var getPosition = function () {
      var deferred = $q.defer();
      if (navigator.geolocation) {
        deferred.resolve(navigator.geolocation.getCurrentPosition(function (position) {
          var crd = position.coords;
          console.log('Latitude : ' + crd.latitude);
          console.log('Longitude: ' + crd.longitude);
          return crd;
        } ));
      }
      return deferred.promise;
  }
  
  // Public API here
  return {
    getPosition: getPosition
  };});
  </code></pre>
  
  <p>My map controller calls it with:</p>
  
  <pre><code>// GEOLOCATION
  geo.getPosition().then( function (position) {
      console.log(position);
      $scope.center.lat = position.latitude;
      $scope.center.lon = position.longitude;
  });
  </code></pre>