Geoloc factory

Hey guys,

I need to be able to use geolocation data from everywhere in the app, so I thought about having a factory give it on demand or retrieve it again on demand and return it. I added the plugin, used NGCordova implementation (maybe I shouldn’t), and wrote this - still a beginner with most Angular features, though.

.factory("GeolocService", [ "$cordovaGeolocation", function($cordovaGeolocation) {
        return {
            currLatLoc : {},
            $setGeoloc : function() {
                $cordovaGeolocation
                    .getCurrentPosition({timeout: 10000, enableHighAccuracy: true})
                    .then(function (position) {
                        return currLatLoc = {"lat": position.coords.latitude, "lon": position.coords.longitude};
                    }, function (err) {
                        return {"error": err}
                    });
            },
            $watchGeoloc : function() {
                $cordovaGeolocation
                    .watchPosition({timeout: 10000, enableHighAccuracy: true})
                    .then( null,
                    function(err) {
                        return {"error": err}
                    },
                    function(position) {
                        return currLatLoc = {"lat": position.coords.latitude, "lon": position.coords.longitude};
                    });
            }
    }
    }]);

But whatever I do in the code later returns empty object or “undefined” :

console.log(GeolocService.currLatLoc);
console.log(GeolocService.$setGeoloc());

I will need your help here guys ! Thank you very much :smile: