Created
September 2, 2016 02:22
-
-
Save thehungrycoder/0ef0ae3e7bbbfae4aea75f29c8304559 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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