S
S
Seva2015-08-02 19:26:57
Angular
Seva, 2015-08-02 19:26:57

Why doesn't navigator.geolocation from services work?

angular.module('events.services', [])
.factory('EventService', function($http, $cordovaSQLite) {
  return {	
        getUserCoords: function() {    
            if (navigator.geolocation) {
                return navigator.geolocation.getCurrentPosition(function(position) {
                    return position;
                })
            }
        }
    }
})

I can't figure out why it
EventService.getUserCoords();
returns undefined. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-08-03
@telray

angular.module('events.services', [])
.factory('EventService', function($http, $cordovaSQLite) {
  return {	
        getUserCoords: function() {    
            if (navigator.geolocation) {
                var p;
                navigator.geolocation.getCurrentPosition(function(position) {
                    p = position;
                });
                return p;
            }
        }
    }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question