【发布时间】:2020-02-11 14:30:26
【问题描述】:
有了这段代码,我可以获取 gps 数据并检索地址,所有这些都可以在后台正常工作,在几分钟内,大约 20 分钟后,应用程序 semms 停止做我想做的事情。 我尝试了电池特许权和其他可能的事情,我尝试了背景服务。 但是在很长一段时间之后,在后台获得位置似乎没有任何作用。 任何建议。
this.backgroundGeolocation.configure(config).then(() => {
console.log('backgroundGeolocation configconfigconfigconfigconfigconfig');
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location).subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
this.ngZone.run(() => {
this.geolocationService.nativeGeocoder.reverseGeocode(location.latitude,
location.longitude).then((result: NativeGeocoderResult[]) =>{
console.log("JSON.stringify(result[0]",JSON.stringify(result[0]));
this.comunenoreplace = result[0]['locality'];
this.comune = result[0]['locality'].replace(/[^A-Z0-9]+/ig, "-");
this.provincia = result[0]['subAdministrativeArea'].replace(new RegExp('Città Metropolitana di|Provincia di', 'g'), '');
this.globalLatitude = location.latitude;
this.globalLongitude = location.longitude;
}).catch((error: any) => console.log("reverseGeocode", error));
});
// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your operations are successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
// this.backgroundGeolocation.finish;
});
});
【问题讨论】:
标签: ionic-framework ionic4 tracking android-gps