use*_*svm 14 ionic-framework ionic2 ionic3 angular
离子的背景地理定位插件未更新.我想要的功能是每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()
}
Run Code Online (Sandbox Code Playgroud)
app.component.ts
constructor(){
this.sendGPSStart()
this.interval()
}
sendGPSStart(){
this.locationTracker.startTracking();
}
sendGPSStop(){
this.locationTracker.stopTracking();
}
interval(){
setInterval(() => {
this.sendGPSStart()
this.sendGPSStop()
}, '30000')
}
Run Code Online (Sandbox Code Playgroud)
查看示例,例如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
};
Run Code Online (Sandbox Code Playgroud)
应用程序组件.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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4829 次 |
| 最近记录: |