Skip to content Skip to sidebar Skip to footer

Update Fields With User Position Using A Service

I would like to update some fields when I receive a geoposition for a give user. Until know I have the following code: http://jsfiddle.net/VSph2/10/ Firstly, I get a Error: Unknown

Solution 1:

Try this. Fiddle

var test = angular.module('myApp', []);
var services = angular.module('myApp.services', []);
services.factory('position', ['$http', function ($http) { ...

should be

var test = angular.module('myApp', []);
test.factory('position', ['$http', function ($http) { ...

You should update the controller code as this, to use a callback function and $apply to apply the value set to the scope.

position.getPosition(function (p) {
    $scope.$apply(function () {
        $scope.position.latitude = p.coords.latitude;
        $scope.position.longitude = p.coords.longitude;
        $scope.position.accuracy = p.coords.accuracy;
    });
});

Post a Comment for "Update Fields With User Position Using A Service"