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

How to make right background geolocation tracking?

$
0
0

The battery drains quickly, how to fix it?

Platform: iOS

My code in background process:

function checkLocation() {
            if (Ti.Geolocation.locationServicesEnabled) {
                Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
                Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
                Ti.Geolocation.getCurrentPosition(function(e) {
                    Ti.API.info('Device Background Tracking Ping');
 
                    if (!e.success || e.error) {
                        Ti.API.info('Device Tracking Error: ' + e.error);
                    } else {
                        var timestamp = parseFloat(e.coords.timestamp);
 
                        if (timestamp - deviceOldTimestamp > 60000) {                       
                            Ti.API.info('Device Tracking Timestamp');
                            exports.sendLocation(e.coords, active_session);
                            deviceOldTimestamp = timestamp;
                        }           
                    }
                });
            } else {
                Ti.API.info('Geolocation Disabled');
                return;
            }
    }
 
if (deviceInterval) {
    clearInterval(deviceInterval);
}
 
deviceInterval = setInterval(checkLocation, 60000);

Viewing all articles
Browse latest Browse all 8068

Trending Articles