gpt4 book ai didi

angular - 背景地理定位 ionic 3 不更新

转载 作者:太空狗 更新时间:2023-10-29 17:01:42 26 4
gpt4 key购买 nike

ionic 的后台地理定位插件未更新。我想要的功能是每 30 秒向插件询问一个 lat lng 值(如果可用)。问题是,它最初只给我值,然后后台停止。前景很好,真的是背景。基本上我无法在后台第一次初始发送后发送请求。

全局定位系统

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();
}

应用程序组件.ts

constructor() {
this.sendGPSStart();
this.interval();
}

sendGPSStart() {
this.locationTracker.startTracking();
}

sendGPSStop() {
this.locationTracker.stopTracking();
}

interval() {
setInterval(() => {
this.sendGPSStart();
this.sendGPSStop();
}, "30000");
}

最佳答案

查看示例,例如 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)

}

关于angular - 背景地理定位 ionic 3 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47385912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com