Answer the question
In order to leave comments, you need to log in
How to follow the Cordova Geolocation Background example?
Good afternoon, in terms of development, I'm a noob. I won't hide it. I want to write a small application for self-development. The project is based on Apache Cordova. I want to run background geolocation, so I chose the plugin https://www.npmjs.com/package/cordova-plugin-mauro... . But I can’t figure out how to execute the simplest example from there:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady () {
/**
* This callback will be executed every time a geolocation is recorded in the background.
*/
var callbackFn = function(location) {
console.log('[js] BackgroundGeoLocation callback: ' + location.latitude + ',' + location.longitude);
// Do your HTTP request here to POST location to your server.
// jQuery.post(url, JSON.stringify(location));
/*
IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
*/
backgroundGeoLocation.finish();
};
var failureFn = function(error) {
console.log('BackgroundGeoLocation error');
};
// BackgroundGeoLocation is highly configurable. See platform specific configuration options
backgroundGeoLocation.configure(callbackFn, failureFn, {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // <-- enable this to clear background location settings when the app terminates
});
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
backgroundGeoLocation.start();
// If you wish to turn OFF background-tracking, call the #stop method.
// backgroundGeoLocation.stop();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question