Hi,
I use the following geolocation service code for android devices to track user location continually :
Ti.App.Properties.setBool("service_running", true); Ti.API.info("Starting geoloc ..."); geolocation(); Ti.API.info("Ending geoloc ..."); Ti.App.Properties.setBool("service_running", false); function geolocation(){ Titanium.Geolocation.Android.manualMode = true; var _gpsProvider = Ti.Geolocation.Android.createLocationProvider( { name : Ti.Geolocation.PROVIDER_GPS,//, minUpdateTime:5, // Max location events per given seconds } ); Ti.Geolocation.Android.addLocationProvider( _gpsProvider ); Ti.Geolocation.pauseLocationUpdateAutomatically = false; Ti.Geolocation.addEventListener('location', function(e) { createNotification('Geolocalisation running ...', "....", "..."); if (!e.success || e.error) { Ti.API.info(e.error); //alert('error ' + JSON.stringify(e.error)); return; } Ti.API.info(e.coords); var longitude = e.coords.longitude; var latitude = e.coords.latitude; var time= +new Date(); coords.push(time+"@"+longitude+"@"+latitude); //alert(apikey); if(Ti.Network.online && apikey != "") { // Sending geoloc data to web server ... } }); }The thing is when I switch to other applications, after several minutes, I stop getting notifications and GPS goes off.
Any idea why ? How can I be sure that even if application is in background, user keeps getting tracked, I need to keep geolocation running while user did not decide to stop definitively the app (even though I know it will drain battery - the purpose is to have a full time tracking app).
Thank you in advance for your time :)