hi, i have a question about continuous location tracking for a long duration of time on Android devices. What i'm trying to do at the moment is create a service that holds the location tracking so that the tracking will continue when the app is being backgrounded. What I can't seem to wrap my head around is how do these two (location and service) work together.
In my understanding a Android service can only be set on an interval, so the service will run the script it is being given every ones in a specified while. Now the service that i'm trying to pass to it, does not need to run/stop every time, it just needs to be set ones and run continiously. In the code below you can see that i'm using a 'location' listener to listen for changes. What hapens now is on every interval the listener gets added, so the first time i get back on location string in the log, the 6th time i get back 6 strings.
so my question really is: how does this work? is there another way besides setting an interval? or should I be using another approach to this problem?
what I have atm:
app.js (register and start service):
// the intent to start var intent_gps_android = Ti.Android.createServiceIntent({ url : 'bgTracking_android.js' }); intent_gps_android.putExtra('interval', 1 * 1000); // every second Ti.Android.startService(intent_gps_android);in my service (bgTracking_android.js)
Titanium.Geolocation.addEventListener( 'location', getPostition); // geo function getPostition(e){ var cString = JSON.parse(Ti.App.Properties.getInt('coords')) var coords = {"lat" : e.coords.latitude , "lon" : e.coords.longitude }; Ti.API.info( JSON.stringify(coords) ); }