using .then() or deferred promise in angular
<p>Very new to JS. Using angular I have a controller in which I would like to call maxmind js library to get the lng/lat of the users IP and simply pop it into the map.setView for mapbox. The only problem is that mapbox of course does not wait for the callback to complete and sets up the map while I'm still doing the callback. A quick search reveals I need to do a .then or a deferred promise coming off of the callback and have the map setup wait for the callback to complete. Having tried both of these I am still having trouble getting it to work. Any suggestions?! Thanks!</p>

<pre><code>    var onSuccess = function(response){
        $scope.lat = response.location.latitude;
        $scope.lng = response.location.longitude;
        console.log($scope.lat, $scope.lng);
    };
    var onError = function(error){
        console.log(error);
    };
    geoip2.city(onSuccess, onError);


    L.mapbox.accessToken = 'token';
    $scope.map = L.mapbox.map('map', 'mapbox.streets', 
        .setView([$scope.lat, $scope.lng], 12)
        .addControl(L.mapbox.geocoderControl('mapbox.places', {
            keepOpen: true
        }));
</code></pre>

<p>Here is the example I was working with</p>

<pre><code>//in my case do the maxmind callback and set vars lat/lng via the res.
var promise = $http.get('/api/v1/movies/avengers');

//in my case setup the map and pass in lat/lng from the callback 
promise.then(
  function(payload) {
    $scope.movieContent = payload.data;
  });
</code></pre>

<p>This seems to work fine for $http in angular but doesn't work with my particular callback which doesn't use $http. I get promise is not defined when I try to set it up.</p>