【发布时间】:2021-10-11 08:30:52
【问题描述】:
我正在开发一个 IONIC 应用程序,该应用程序在谷歌地图上显示服务提供商的活动位置,目的地为用户 (lat,lon),来源为服务提供商的活动位置 (lat,lon)。
一旦服务提供商按下按钮,我们将使用“ionic cordova plugin add @mauron85/cordova-plugin-background-geolocation”插件获取他的位置,以在 30 秒后获取服务提供商的位置。
应用在前台时有效,但在应用处于非活动状态或后序时失败。
如果需要,我还使用“ionic cordova plugin add cordova-plugin-background-mode”来启用后台进程。但问题仍然存在。
如果APP在后台,我无法获取服务提供商的位置。
我在构造函数中的代码如下:
this.backgroundGeolocation.configure(this.config).then(() =>
{
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location).subscribe((location: BackgroundGeolocationResponse) =>
{
this.latitude = String(location.latitude);
this.longitude = String(location.longitude);
this.saveCordinates();
});
});
每 30 秒后我使用 this.backgroundGeolocation.start();
初始化填充 this.latitude, this.longitude 然后我用 this.saveCordinates();功能
【问题讨论】:
标签: ionic-framework