简体   繁体   English

如何根据用户的旅行距离使应用更新服务器?

[英]How to make an app updates a server based on the distance the user has traveled?

I want to get notified whenever a user travel specific distance like 500m or 1km, no matter what the app state is, even if the app is in foreground, background, or suspended. 无论应用程序处于什么状态,即使应用程序处于前景,背景或暂停状态,我都希望在用户行驶特定距离(例如500m或1km)时得到通知。 and updated the user coordinates to server by making an api call. 并通过api调用将用户坐标更新到服务器。

What would be the proper way to implement this? 实施此方法的正确方法是什么?

I do not think it is possible if the app is in suspended state, other than that, for foreground/background you can do that. 我认为,如果应用程序处于挂起状态是不可能的,除此之外,对于前景/背景,您可以这样做。

You can use a timer to check location while your app is in background. 当您的应用程序在后台运行时,您可以使用计时器检查位置。 please check the following repo, you will get an idea how to do that. 请检查以下回购,您将了解如何执行此操作。 https://github.com/voyage11/Location https://github.com/voyage11/位置

You only allow to access the location in foreground / background mode. 您仅允许以前台/后台模式访问该位置。 To called location delegate in background mode you need to call startMonitoringSignificantLocationChanges . 要在后台模式下调用位置委托,您需要调用startMonitoringSignificantLocationChanges

This method will check for 500m changes in location and call location delegate method after 500m changes in between your current location and previous. 此方法将检查位置是否有500m更改,并在当前位置和先前位置之间发生500m更改后调用位置委托方法。

Let me know if you have any query on the same. 让我知道您是否有相同的查询。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM