ionic vue 背景地理定位跟踪在 5 分钟后停止
Posted
技术标签:
【中文标题】ionic vue 背景地理定位跟踪在 5 分钟后停止【英文标题】:ionic vue background geolocation tracking stops after 5 minute 【发布时间】:2021-04-30 17:58:18 【问题描述】:我正在使用插件https://github.com/seididieci/capacitor-backround-geolocation 观察用户的位置。然后我在推杆的帮助下跟踪那个位置。此背景位置仅在停止后工作 5 分钟。我正在使用电容器的后台任务。但该插件还会在用户打开应用程序后将数据保存在手机上。后台任务向推送器发送数据。
这是手表定位功能
getLocation: async function ()
BackgroundGeolocation.initialize(
notificationText: "Your app is running, tap to open.",
notificationTitle: "App Running",
updateInterval: 10000,
requestedAccuracy: BgGeolocationAccuracy.HIGH_ACCURACY,
// Small icon has to be in 'drawable' resources of your app
// if you does not provide one (or it is not found) a fallback icon will be used.
smallIcon: "ic_small_icon",
// Start getting location updates right away. You can set this to false or not set at all (se below).
startImmediately: true,
);
// const geolocation = new Geolocation.Geolocation();
BackgroundGeolocation.addListener("onLocation", (location) =>
// console.log("Got new location", location);
this.subscribe(location.longitude, location.latitude);
console.log(location)
);
BackgroundGeolocation.addListener("onPermissions", (location) =>
// console.log("BGLocation permissions:", location);
this.subscribe(location.longitude, location.latitude);
// Do something with data
);
BackgroundGeolocation.start();
,
然后在mounted()中调用函数
mounted()
this.getLocation
App.addListener("appStateChange", (state) =>
setInterval(this.getLocation, 120000);
if (!state.isActive)
BackgroundTask.beforeExit(async () =>
setInterval(this.getLocation, 120000);
console.og('Why')
);
if (state.isActive)
setInterval(this.getLocation, 120000);
console.log('Active')
);
【问题讨论】:
【参考方案1】:您需要像这样使用https://ionicframework.com/docs/native/foreground-service 来运行后台。
【讨论】:
以上是关于ionic vue 背景地理定位跟踪在 5 分钟后停止的主要内容,如果未能解决你的问题,请参考以下文章
我应该多久在 Ionic 2 中跟踪设备位置(例如 Uber、Taxi Apps、...)