【发布时间】:2020-04-22 06:46:05
【问题描述】:
当应用程序在 Ionic 3 中处于后台时,Cordova 插件 background-geolocation 不起作用。此代码在 app.component.ts 文件中调用。此代码仅在前台调用该 web 服务,而不是在后台或屏幕关闭。
startTracking() {
// Background Tracking
let config = {
desiredAccuracy: 0,
stationaryRadius: 20,
distanceFilter: 10,
debug: true,
interval: 2000
};
this.backgroundGeolocation.configure(config).subscribe((location) => {
console.log('BackgroundGeolocation: ' + location.latitude + ',' + location.longitude);
// Run update inside of Angular's zone
this.zone.run(() => {
this.geoLatitude = location.latitude;
this.geoLongitude = location.longitude;
this.TrackLiveLocation();//for call our private webservice
});
});
}, (err) => {
console.log(err);
});
// Turn ON the background-geolocation system.
this.backgroundGeolocation.start();
// Foreground Tracking
let options = {
frequency: 3000,
enableHighAccuracy: true
};
this.watch = this.geolocation.watchPosition(options).filter((p: any) => p.code === undefined).subscribe((position: Geoposition) => {
console.log(position);
// Run update inside of Angular's zone
this.zone.run(() => {
this.geoLatitude = position.coords.latitude;
this.geoLongitude = position.coords.longitude;
this.TrackLiveLocation();//for call our private webservice
});
});
}
【问题讨论】:
标签: android background geolocation ionic3 tracking