Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Android GPS tracking 'Best Practice'.

$
0
0

Hi Guys. I can't find some answers in regards to GPS tracking so wanted to ask them here.

I have an Android app which needs to track the user at all times. I wast to have GPS running at all times, when the app is in view or in the background. Battery life will be an issue so i want to make it as battery friendly as possible.

At the moment, I'm using this code to track location changes and track the user:

Titanium.Geolocation.frequency = 1;
Titanium.Geolocation.Android.manualMode = true;
 
var gpsProvider = Titanium.Geolocation.Android.createLocationProvider({
     name : Titanium.Geolocation.PROVIDER_GPS,
     minUpdateTime : 30, 
     minUpdateDistance : 80
});
 
Titanium.Geolocation.Android.addLocationProvider(gpsProvider); 
 
gpsProvider.minUpdateTime = 30;
gpsProvider.minUpdateDistance = 80;
 
var locationCallback = function(e) {
    if (!e.success || e.error) {
        Ti.API.info('error:' + JSON.stringify(e.error));
    } else {
        Ti.API.info('TRACKING: Timestamp:' + e.coords.timestamp +' Speed:'+ e.coords.speed +' Heading:'+ e.coords.heading +' Latitude:'+ e.coords.latitude +' Longitude:'+ e.coords.longitude);
        db.execute('INSERT INTO tracking (timestamp,speed,heading,lat,lon) VALUES (?,?,?,?,?)', e.coords.timestamp, e.coords.speed, e.coords.heading, e.coords.latitude, e.coords.longitude);
    }
};
Titanium.Geolocation.addEventListener('location', locationCallback);
Will this continually track the user even when the app is idle for long periods of time and when the app is running in the background? Do i need to create a background service? Is this the best method for conserving battery life? Thanks Adam.

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>