Hello,
I am using Background Geolocation for my app, but it doesn’t work properly, this is how i start tracking :
startTracking(idDep) {
let counter : number = 0;
return new Promise((resolve, reject) => {
// Background Tracking
this.diagnostic.isLocationAuthorized().then(enabled => {
if(!enabled){
this.diagnostic.requestLocationAuthorization().then( status => {
console.log("Authorization status is now: "+status);
}, (error) => {
console.error(error);
reject(false);
});
}
this.locationAccuracy.canRequest().then((canRequest: boolean) => {
if(canRequest) {
// the accuracy option will be ignored by iOS
this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
() => {
let config = {
desiredAccuracy: 0,
stationaryRadius: 1,
distanceFilter: 1,
notificationTitle: 'Background tracking',
notificationText: 'enabled',
debug: true,
stopOnTerminate: true,
Mode: 0
};
this.backgroundGeolocation.configure(config).subscribe((location) => {
console.log('BackgroundGeolocation: ' + location.latitude + ',' + location.longitude);
// Run update inside of Angular's zone
this.zone.run(() => {
this.lat = location.latitude;
this.lng = location.longitude;
this.update_technician_location(idDep,this.lat,this.lng).then(
(val) => {
console.log("val = "+val);
if(!val){
if(this.watch != null){
this.backgroundGeolocation.stop();
this.watch.unsubscribe();
this.watch = null;
}
}
},
(err) => {
if(this.watch != null){
this.backgroundGeolocation.stop();
this.watch.unsubscribe();
this.watch = null;
}
}
);
resolve(true);
});
}, (err) => {
console.log(err);
reject(false);
});
// Turn ON the background-geolocation system.
this.backgroundGeolocation.start();
//Foreground Tracking
let options = {
frequency: 3000,
enableHighAccuracy: true
};
this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {
console.log(position);
// Run update inside of Angular's zone
this.zone.run(() => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
this.update_technician_location(idDep,this.lat,this.lng).then(
(val) => {
console.log("val = "+val);
if(!val){
if(this.watch != null){
this.backgroundGeolocation.stop();
this.watch.unsubscribe();
this.watch = null;
}
}
},
(err) => {
if(this.watch != null){
this.backgroundGeolocation.stop();
this.watch.unsubscribe();
this.watch = null;
}
}
);
resolve(true);
});
});
});
}
});
});
});
}
i have tried many parameters on the config, but it still updates randomely, and sometimes it doesn’t update at all, is there something wrong with the plugin ? if not any solution?