i try it but it giving issue i started it on click but it not working in background? Like this
startBackgroundGeolocation() {
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 1,
distanceFilter: 1,
interval:15000,
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) => {
// alert(location.longitude);
this.sendGPS(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 operations are successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
});
});
// start recording location
this.backgroundGeolocation.start();
// If you wish to turn OFF background-tracking, call the #stop method.
// this.backgroundGeolocation.stop();
}
sendGPS(location) {
if (location.speed == undefined) {
location.speed = 0;
}
let timestamp = new Date(location.time);
this.http
.post(
this.gps_update_link, // backend api to post
{
lat: location.latitude,
lng: location.longitude,
speed: location.speed,
timestamp: timestamp
},
{}
)
.then(data => {
this.Data.push({lat : location.latitude , lon : location.longitude , spe : location.speed , time : location.timestamp});
console.log(data.status);
console.log(data.data); // data received by server
console.log(data.headers);
this.backgroundGeolocation.finish(); // FOR IOS ONLY
})
.catch(error => {
alert(error.status);
alert(error.error); // error message as string
alert(error.headers);
this.backgroundGeolocation.finish(); // FOR IOS ONLY
});
}
This is a code i am using please inform me what i am doing wrong?
Hello
after android 8 android os will your background tracking for security reason. background geolocation tracking working fine on android 8 but after android 9 this is not working
i try it but it giving issue i started it on click but it not working in background? Like this
startBackgroundGeolocation() { const config: BackgroundGeolocationConfig = { desiredAccuracy: 10, stationaryRadius: 1, distanceFilter: 1, interval:15000, debug: true, // enable this hear sounds for background-geolocation life-cycle. stopOnTerminate: false // enable this to clear background location settings when the app terminates
}
sendGPS(location) { if (location.speed == undefined) { location.speed = 0; } let timestamp = new Date(location.time);
}
This is a code i am using please inform me what i am doing wrong?