Я использую код, подобный этому, но он не отправляет запрос на мой сервер? Я отправляю запрос через него на мой сервер, но он не изменяет его, а когда я его открываю, отправляю запрос на мой сервер. я что бы отслеживать лат и логиниться через него.
startBackgroundGeolocation() {
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 1,
distanceFilter: 1,
interval:1000,
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
});
}
пожалуйста сообщите мне, что я делаю не так? Спасибо