I'm currently developing a Cordova application that utilizes different AngularJS states. Strangely, when I call geolocation.watchposition in the first state, everything works perfectly fine. However, if I try to call it in the second state, I encounter an "access denied" issue.
State transitions are triggered by a button click. Interestingly, regardless of which state I start with, only the first state seems to have access to GPS while the second one doesn't.
EDIT: It's worth mentioning that this setup works without any issues in a browser, but fails on my Android device.
Any ideas on what might be causing this discrepancy?
index.js
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
templateUrl: 'templates/main_menu.html',
controller: 'AppCtrl'
})
.state('map', {
url: '/map',
templateUrl: 'templates/map.html',
controller: 'MapCtrl'
});
//First State
$urlRouterProvider.otherwise('/app');
});
controller.js
.controller('AppCtrl', function ($scope, $rootScope, $ionicHistory, $http, $window) {
$scope.accPos = function () {
var id, target, options;
function success(pos) {
alert("Pos: " + pos.coords.latitude + " " + pos.coords.longitude);
}
function error(err) {
alert('ERROR(' + err.code + '): ' + err.message);
}
options = {
enableHighAccuracy: false,
timeout: 6000,
maximumAge: 0
};
id = navigator.geolocation.watchPosition(success, error, options);
};
$scope.accPos();
}
//The following code block looks exactly the same
.controller('MapCtrl', function ($scope, $rootScope, $ionicHistory, $http, $window) { ... }