开发者

Android location updates interval

开发者 https://www.devze.com 2023-03-31 13:08 出处:网络
I am experimenting with Androids location updates. The requestLocationUpdates is responsible for providing the updates. With the following code:

I am experimenting with Androids location updates. The requestLocationUpdates is responsible for providing the updates. With the following code:

locationManager.requestLocationUpdate开发者_C百科s(provider, 300000, 10, this);

I am only supposed to receive updates 5 minutes and 10 meters apart. But the updates just keep coming in seconds apart and even when I am sitting still.

GPS is the provider I am using.

I need to space the updates out. What can I try?


The 10m is too small - I would increase that. GPS accuracy isn't great, and so every time it senses a small difference you will get another location. I'd bump it up to 100m and I expect you will then get a sensible number of locations coming through.

If you do want it more specific, then you'll need to handle the volume as more accurate means more volume.


Hers what i'd do:

  1. First of all I check what providers are enabled. Some may be disabled on the device, some may be disabled in application manifest.
  2. If any provider is available I start location listeners and timeout timer. It's 20 seconds in my example, may not be enough for GPS so you can enlarge it.
  3. If I get update from location listener I use the provided value. I stop listeners and timer.
  4. If I don't get any updates and timer elapses I have to use last known values.
  5. I grab last known values from available providers and choose the most recent of them.

The 10m is too small for a GPS reading, try 100m. You'll also have issues with power saving mode, and app battery optimisation on most Android phones.

Android 10 and above has very strict background location updates, and may kill apps that run in the background. Later versions will also remove apps that have not be used recently.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号