Part 1 : the geolocation: it's better to use watchPosition for a couple of seconds than to use getCurrentPosition. ( use watchPosition for 15 or 25 seconds or so... keeping coordinates as they come in only if the accuracy is better than the last coordinate. then stop it and keep the last, most accurate coordinate. ) Repeat this again when you want to capture the position later.
Part 2 : keeping the application 'alive' even when the phone is 'sleeping' :
you need the Background-mode plugin :
cordova plugin add de.appplant.cordova.plugin.background-mode
and my version of the Power Management Plugin
cordova plugin add https://github.com/boltex/cordova-plugin-powermanagement.git
Then in your app.js "run" method of your main angular module, you put this in the $ionicPlatform.ready function :
if( ionic.Platform.isAndroid() ){
cordova.plugins.backgroundMode.enable();
window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
}, function() {
console.log('Failed to set');
});
}
There.... you're done. The application will remain "alive" and trigger all your timeouts even when the screen turns black and the phone is 'sleeping'.
If you also needed some push notifications it will be messed up... so you need to use another plugin that I modified specially for this.
cordova plugin add https://github.com/boltex/PushPlugin.git
ask me again if you need it = Hope this helps