Skip to content

Instantly share code, notes, and snippets.

@Cengizism
Created March 19, 2014 12:28
Show Gist options
  • Save Cengizism/842d2b2abba071f5e704 to your computer and use it in GitHub Desktop.
Save Cengizism/842d2b2abba071f5e704 to your computer and use it in GitHub Desktop.
angular-geolocation
angular.module('ngGeolocation',[])
.constant('options',{})
.factory('geolocation',
["$q","$rootScope","options",
function ($q , $rootScope , options){
return {
position: function () {
var deferred = $q.defer()
navigator.geolocation.getCurrentPosition(function (pos) {
$rootScope.$apply(function () {
deferred.resolve(angular.copy(pos))
})
}, function (error) {
$rootScope.$apply(function () {
deferred.reject(error)
})
},options)
return deferred.promise
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment