ngGeolocation
ngGeolocation copied to clipboard
Illegal invocation $apply when using watchPosition
I am using the google maps example. Angular 1.4.3 gives me several 'illegal invocation' errors.
TypeError: Illegal invocation at equals (angular.js:1039) at equals (angular.js:1039) at Scope.parent.$get.Scope.$digest (angular.js:15677) at Scope.parent.$get.Scope.$apply (angular.js:15951) at retVal.watchPosition.options.watchId.$window.navigator.geolocation.watchPosition.$rootScope.$apply.retVal.position.error (ngGeolocation.js:43)
Do you know how to solve this?
Can you paste the code that you are using to call watchPosition
?
I'm seeing this too (not using angular-google-maps though). Note the example shown on the README seems wrong. Watching 'myPosition.position' is being watch by the scope, but that is not a scope variable.
I've tried to watch $geolocation.position in two ways:
$scope.$watch(function(){ return $geolocation.position; }, function() { ...})
$scope.$geolocation = $geolocation;
$scope.$watch('$geolocation.position', function() {});
I've had issues with the example as well, until I realized that it's wrong. Reading the code, you can see that, when the position change, it emits an event with the tag '$geolocation.position.changed', so in your controller you have to use:
$scope.$on('$geolocation.position.changed', function(event, newPosition){
console.log(newPosition); //This is the current position
})
Thanks, it was exactly what I was looking for. Why not to update the readme?
Feel free to update the readme and send a pr. I'm in Greece at the moment working with refugees and don't have a computer with me so can't do it myself. Thanks
On Thu, 21 Jan 2016 22:11 Pierluigi Petrelli [email protected] wrote:
Thanks, it was exactly what I was looking for. Why not to update the readme?
— Reply to this email directly or view it on GitHub https://github.com/ninjatronic/ngGeolocation/issues/21#issuecomment-173694483 .
I had the same. After 2 hours of debugging I realized, that the example is wrong. Please update the example.