Combine $http and $cordovaGeolocation results


#1

I have nex workflow: when user open some view, his location should be found, and then http request should be sent and afterwards response parsed into view. I have resolved this by nesting callbacks in controller,

var posOptions = {timeout: 10000, enableHighAccuracy: false};

$ionicLoading.show({
template: ‘Loading Location’
});
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
Explore.explore(lat, long).then(function (result) {
exploreCallback(result);

        },
        function (err){
            alert(err);
            $ionicLoading.hide();

        });
}, function (err) {
    Explore.explore().then(function (result) {
        exploreCallback(result);
    });
});

    function exploreCallback(result) {
        $scope.serviceTypes = ServiceTypes;
        $scope.explore = result.data;
        $ionicLoading.hide();
    };

I’m sure that there’s a better way to achive this. When I have only http service I’ve used a resolve directive in state declaration, but I’m unable to achieve same with 2 services.

Any suggestions?