LocationManager calling onLocationChanged too often?

后端 未结 3 622
借酒劲吻你
借酒劲吻你 2021-02-03 12:14

I\'ve set up the LocationManager to get the current location every 2 minutes:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 120000, 0, thi         


        
3条回答
  •  难免孤独
    2021-02-03 13:17

    I found this question because I had the same problem.

    I believe I have the answer. The rapid updates are being fired because you have the meters parameter set to 0.

    Change the meters parameter to something like 10 and it will only fire the LocationChanged event every 2 minutes IF your location changed by 10 or more.

    Before I made this change, LocationChanged was firing multiple times a second. Now, it fires once. Then every 2 minutes, you will see the GPS icon on the status bar, but unless your location changed, the event doesn't fire.

    I hope this helps. This is what fixed it for me. Didn't have to add any extra logic to prevent false fires.

提交回复
热议问题