Skip to content

Instantly share code, notes, and snippets.

@thehungrycoder
Created September 2, 2016 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehungrycoder/0ef0ae3e7bbbfae4aea75f29c8304559 to your computer and use it in GitHub Desktop.
Save thehungrycoder/0ef0ae3e7bbbfae4aea75f29c8304559 to your computer and use it in GitHub Desktop.
angular.module('myapp.services', [])
.service('LocationService', function ($cordovaGeolocation, $q) {
return {
askLocationPermission: function () {
var permissions = cordova.plugins.permissions, // could not find a better way to access cordova; it's not in $window
deferred = $q.defer();
permissions.requestPermission(permissions.ACCESS_COARSE_LOCATION, function(result) {
deferred.resolve();
}, function(err) {
deferred.reject(err);
});
return deferred.promise;
},
getCoords: function () {
return $cordovaGeolocation.getCurrentPosition({timeout: 10000, enableHighAccuracy: false})
.then(function (position) {
return position.coords;
});
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment