背景地理定位在背景中的离子3中不起作用



Cordova插件后台地理定位在Ionic 3中应用程序处于后台时不起作用。此代码在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
});
});
}

Native v/s Hybrid安卓8最新更新的一个副作用是,定位API将需要本地应用程序开发。因为通过React Native、Flutter、Cordova、Ionic或Xamarin等混合框架进行的直接控制将不再有效。混合应用程序开发人员将需要为位置访问构建本机功能。

根据最新的Android政策和后台服务更新,ionic插件适用于前台,但不适用于后台。

后台模式的策略

最新更新