Problem with background geolocation plugin functions

Hello guys,

I installed and configured background geolocation plugin (
https://github.com/mauron85/cordova-plugin-background-geolocation ) with no problems.

let config: BackgroundGeolocationConfig = {
    desiredAccuracy: 10,
    stationaryRadius: 1,
    distanceFilter: 1, 
    debug: true,
    interval: 2000,
    stopOnTerminate: false,
    url: 'my-link',
    postTemplate: {
        lat: '@latitude',
        lng: '@longitude'
};
		
this.backgroundGeolocation.configure(config).then((location: BackgroundGeolocationResponse)=>{
    this.globals.lat = location.latitude;
    this.globals.lng = location.longitude;
    this.storage.set('lat',location.latitude);
    this.storage.set('lng',location.longitude);
}, (error) => {
    alert(error);
});

this.backgroundGeolocation.start();

The coords are saved to server every time the location changes, even if my app is completely closed. The problem is that when there is not internet connection i want to save locations to a local sqlite table and when internet connection returns send this table to server, and I dont know the function-listener of plugin where i have to put my “write to sqlite table” code. The function

BackgroundGeolocation.on('location', function(location) {...});

causes build error with the message that expected 1 argument. Could anyone help me???

After searching deep in the plugin’s files i found the solution, which is far away from the ionic documentation

import {
    BackgroundGeolocation ,
    BackgroundGeolocationConfig ,
    BackgroundGeolocationResponse ,
    BackgroundGeolocationLocationProvider,
    BackgroundGeolocationEvents
} from '@ionic-native/background-geolocation';

this.backgroundGeolocation.on(BackgroundGeolocationEvents['location']).subscribe((location) => { 
    ...
});
1 Like