Geolocationworks first time, then fails

Heey, so i’ve noticed that the geolocation works when the app starts but when i go to another view and go back to the view with the controller that needs it it doesn’t work, i tried to recreate it in a codepen and there it sort of sometimes kinda works and idk what’s happening, is there anyone that knows why it doesn’t get my location when i go back to that controller/view?


See the Pen Toggle: 1.0.0-beta.11 by Sjoerd de Wit (@sjerd) on CodePen.

Also found the exact same issue on the ngcordova github

I recommend you ngCordova, done by ionic guys. So nice!

But, if you can’t or don’t want to use it, you have to choices:

First one, wrap geolocation success callback into a $scope.$apply();

$scope.$apply(function() {
    //whateve here
    //you can use $scope
    $scope.done = true;

Even, you can call $scope.$apply() without arguments, but there is some differences.

Another way is to use deferred object (Like ngCordova do)

Hope this helps

i’m actually using ngCordova :slight_smile: just wanted to make a quick pen to demonstrate the issue. and i’ve tried wrapping it with $scope.$apply and $timeout and none of them updated my location…

Is this problem only apparent with ios8 for you? We had issues exactly as you described which were related to the cordova geolocation plugin. If this is the actual problem I’ll find the fix that worked for us and post it for you.

No, it’s accross all platforms browser/android/ios

Did you find a solution or a workaround?

I did actually, i’ve put the location update in my main ctrl src:

		var mainloop;
	$scope.startloop = function(){
		if ( angular.isDefined(mainloop) ) return;
		mainloop = $interval(function(){
			var options = {
			  enableHighAccuracy: true,
			  maximumAge: 0,
			  timeout: 10000
			$cordovaGeolocation.getCurrentPosition(options).then(function (pos) {
				latlong =  { 'lat' : pos.coords.latitude, 'long' : pos.coords.longitude };
				$rootScope.currentLocation = latlong;
			}, function(err) {
	$scope.stoploop = function(){
		if (angular.isDefined(mainloop)) {
			mainloop = undefined;
	$scope.$on('$destroy', function() {
      // Make sure that the interval is destroyed too

	var app = document.URL.indexOf( 'http://' ) === -1 && document.URL.indexOf( 'https://' ) === -1;
	if ( app ) {
		cordova.plugins.backgroundMode.onactivate = function () {
		cordova.plugins.backgroundMode.ondeactivate = function() {

I’m running into the same issue as you, can you post your solution?

I’m having the exact same issue. Anyone know a fix?

I had solved it, and guilty also of not posting the solution. :confused:

It seems in iOS 8 the GPS permissions had fundamentally changed. I had to disable high accuracy in the options for this the plugin to work. I’m not sure of the root cause, but this was the work around that I’ve used with great success.

The plugin likely needs some updates from someone more familiar with ObjC.

var options = {
  enableHighAccuracy: false,

Edit: Somehow I now have two accounts. Go figure…