I use cordova background geolocaiton plugin in my ionic 3 application.
ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@alpha
npm install --save @ionic-native/background-geolocation@4
I expect the plugin work in background, once the device is moved over 40 meters, the plugin will trigger this.backgroundGeolocation.on(BackgroundGeolocationEvents.location)
once, My code is like:
startBackgroundGeolocation() {
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 40,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false // enable this to clear background location settings when the app terminates
};
this.backgroundGeolocation.configure(config).then(() => {
this.backgroundGeolocation
.on(BackgroundGeolocationEvents.location)
.subscribe((location: BackgroundGeolocationResponse) => {
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!");
console.log(location);
});
});
this.backgroundGeolocation.start()
}
But after backgroundGeolocation start, I find the behavior is not like my expectation.
-
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location)
is triggered about ever 30 seconds without any device movement -
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location)
has been triggered many times, and the number of times increases one every ~30 seconds
for example, when it is first triggered, the log shows:
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
in about 30 seconds, it is second triggered, log shows:
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
in next about 30 seconds, it is third triggered, log shows:
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
and so on.
I want .on(position)
only be triggered when movement over 40 meters, and when it is triggered, just triggered once.
!!!!!!!!!!!!!!!!!!!!!!!!!! background geolocation !!!!!!!!!!!!!!!!!!!
I think there must be something wrong with my configuration setting, but I could not find the problem in the setting.
Could you please help if you familiar with cordova-background-geolocation plugin?
Thanks