Purpose of the application: to get geolocation at each turn and the place of registration when the application is in the foreground and in the background.
I tried so much code and combination, but I can not get it to work (after 2 days ...).
Classic geolocation (getCurrentPosition) works fine, but when we close the application, background geolocation starts, but nothing happens ... The "callbackFn" function never starts.
I am testing iOS using xcode> Audio Features and Location Activated for Background Activity. I also did the work with the jQuery example example specified in the plugin, so I saw that it works, but never with ionic / angular ones.
Here is the current controller processing the background:
.controller('TestCtrl', function($scope, $timeout, $cordovaBackgroundGeolocation, $ionicPlatform, $window)
{
$scope.lat_geo = "loading lat...";
$scope.long_geo = "loading long...";
var options = {
enableHighAccuracy : false,
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 5,
notificationTitle: 'Background tracking',
notificationText: 'ENABLED',
activityType: 'AutomotiveNavigation',
debug: true,
stopOnTerminate: false
};
$ionicPlatform.ready(function()
{
console.log("[IONIC PLATFORM IS NOW READY]");
navigator.geolocation.getCurrentPosition(function(location) {
console.log('[GEOLOCAL JS1] Location from Phonegap');
},
function (error){
console.log('[GEOLOCAL JS1] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
},options);
var callbackFn = function(location) {
console.log('[BackgroundGeoLocation] Update callback: ' + location.latitude + ',' + location.longitude);
};
var failureFn = function(error) {
console.log('[BackgroundGeoLocation] Error: '+error);
};
$cordovaBackgroundGeolocation.configure(callbackFn, failureFn, options);
$cordovaBackgroundGeolocation.start();
$timeout(function()
{
navigator.geolocation.getCurrentPosition(function(location)
{
console.log('[GEOLOCAL JS3] Location from Phonegap');
startPos = location;
$scope.$apply(function () {
$scope.lat_geo = startPos.coords.latitude;
$scope.long_geo = startPos.coords.longitude;
});
console.log("[GEOLOCAL BASIC] OK this time :)");
},
function (error){
console.log('[GEOLOCAL JS3] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
},options);
}, 3000);
});
})
( ) github: https://github.com/Jeff86/ionic_ngcordova_backgroundgeo_test/tree/master