This is just a snippet. For a working example see JSFidde: http://jsfiddle.net/robhurring/eVBug/light/
Angular geolocation wrapper service
app.factory("GeolocationService", ['$q', '$window', '$rootScope', function($q, $window, $rootScope){ | |
return function(){ | |
var deferred = $q.defer(); | |
if(!$window.navigator) { | |
deferred.reject("Geolocation is not supported"); | |
} else { | |
$window.navigator.geolocation.getCurrentPosition(function(position) { | |
$rootScope.$apply(function(){ | |
deferred.resolve(position); | |
}); | |
}); | |
} | |
return deferred.promise; | |
} | |
}]); |
This comment has been minimized.
This comment has been minimized.
Should if (!$window.navigator) be if (!$window.navigator.geolocation) ?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Awesome, thanks a million!
Line 16 in service missing semi-colon ;)