android LocationManager.requestLocationUpdates with minTime >0 not working as expected

后端 未结 1 1458
既然无缘
既然无缘 2020-12-19 18:26

I set

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0f, this);

it has an odd behavior, locationChanged gets called e

1条回答
  •  有刺的猬
    2020-12-19 19:10

    The minTime (60000) is just a hint, and there's no guarantee that your locationlistener will kick in at an exact 1 minute interval. Combined with the minDistance=0, you'll probably receive a lot more updates.

    I would increase the minDistance to 1m minimum, and implement compensation logic to achieve the 1 minute interval in your code. You LocationListener can be implemented in such a way that if location updates follow too closely, they are ignored and not processed.

    You'll also get different locations through your location listener, with a different accuracy, all within that minute interval.

    Your location listener can pick the best accuracy, and remember when the last location was processed by maintaining state (lastLocationProcessedAt).

    0 讨论(0)
提交回复
热议问题