Background geolocation ionic 3 не обновляется
Фоновый геолокационный плагин для ионного не обновляется. Функциональность, которую я хочу, каждые 30 секунд запрашивает плагин для значения lat lng, если он доступен. Проблема в том, что он сначала дает мне значения, а затем останавливается фон. На переднем плане все в порядке, это действительно фон. В принципе, я не могу отправлять запросы после первой начальной отправки в фоновом режиме.
gps.ts
startTracking() {
console.log('started tracking')
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false
};
this.backgroundGeolocation.configure(config)
.subscribe((location: BackgroundGeolocationResponse) => {
this.zone.run(() => {
this.lat = location.latitude
this.lng = location.longitude
this.bearing = location.bearing
this.speed = location.speed
this.accuracy = location.accuracy
this.timestamp = location.time
})
this.backgroundGeolocation.finish(); // FOR IOS ONLY
this.backgroundGeolocation.stop()
});
this.backgroundGeolocation.start();
}
sendGPS(){
this.optionsService.sendGPS(gpsData).subscribe(result => {
}
})
}
stopTracking() {
this.sendGPS()
}
app.component.ts
constructor(){
this.sendGPSStart()
this.interval()
}
sendGPSStart(){
this.locationTracker.startTracking();
}
sendGPSStop(){
this.locationTracker.stopTracking();
}
interval(){
setInterval(() => {
this.sendGPSStart()
this.sendGPSStop()
}, '30000')
}
Ответы
Ответ 1
Глядя на примеры, например dnchia/Ionic3-Background-Geolocation, вы должны настроить интервал на фоне, а также периодическую отправку переднего плана
gps.ts
startTracking(interval) {
console.log('started tracking')
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false,
interval: interval
};
app.component.ts
interval = 30000;
constructor() {
this.sendGPSStart()
this.interval()
}
sendGPSStart(){
this.locationTracker.startTracking(this.interval);
}
sendGPSStop(){
this.locationTracker.stopTracking();
}
interval() {
setInterval(() => {
this.locationTracker.sendGPS();
}, this.interval)
}
Ответ 2
В настоящее время об отчетах об ошибках на проектах github:
См:
https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/548
а также
https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/539
Создатель проекта предлагает удалить плагин с заставкой (плагин-плагин-заставку)