I’ve been following a tutorial by the great Josh Morony, and I am not able to get the interval to consistently produce a console log of the current speed of the device. It seems to ignore the interval set, and when setting the interval to 1000 it does not return a response every second, as shown below.
[19:43:45] console.log: BackgroundGeolocationSpeed 0
[19:45:18] console.log: BackgroundGeolocationSpeed 0.7200000286102295
[19:45:27] console.log: BackgroundGeolocationSpeed 0
[19:48:53] console.log: BackgroundGeolocationSpeed 0
[20:24:04] console.log: BackgroundGeolocationSpeed 0.7900000214576721
[20:24:07] console.log: BackgroundGeolocationSpeed 1.4199999570846558
[20:24:11] console.log: BackgroundGeolocationSpeed 1.5299999713897705
As you can also see, sometimes a log will not be produced for a long time and I was wondering what causes this, as it seemed to only produce more console logs when i just clicked on the terminal again.
I need this to run in the background because I am using it to prevent notifications from being triggered when the user is driving (e.g. travelling over 15mph) so that they do not get distracted.
In my SpeedTracker provider:
startTracking() {
let config = {
desiredAccuracy: 0,
stationaryRadius: 20,
distanceFilter: 10,
debug: false,
interval: 1000
};
BackgroundGeolocation.configure((location) => {
// Run update inside of Angular's zone
this.zone.run(() => {
this.speed = location.speed;
console.log("BackgroundGeolocationSpeed " + location.speed);
});
}, (err) => {
console.log(err);
}, config);
// Turn ON the background-geolocation system.
BackgroundGeolocation.start();
}
This is started in app.component.ts.
Any help?