Skip to content

Instantly share code, notes, and snippets.

Last active March 3, 2016 11:58
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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) {
return deferred.promise;
app.controller('MainCtrl', ['$scope','GeolocationService', function($scope, geolocation){
$scope.position = null;
geolocation().then(function(position) {
$scope.position = position;
Copy link

Awesome, thanks a million!

Line 16 in service missing semi-colon ;)

Copy link

ximon commented Mar 3, 2016

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