0

I have the same problem with this. FusedLocationProviderClient getLastLocation elapsedRealtimeNanos mostly current system time

My code currently compares the time value of location by FLP getLastLocation() with the current time value and requests a new location if 5 seconds have passed.

At some point, however, the value(current time - last location time) continues to be zero seconds. I don't know how to solve it.

The steps for requesting location are as follows:

  1. Request FusedLocationProviderClient.getLastLocation()

  2. Determine if lastLocation was acquired within 5 seconds of the current time

    • Use location information within 5 seconds, end of the process
  3. Request a new location update if 5 seconds have been elapsed (Request both Location manager and FLP)

  4. Remove all location update requests if new locations have been updated via Location manager or FLP

    age = time diff : (SystemClock.elapsedRealtimeNanos() - getElapsedRealtimeNanos() of passed location) / 1000000000L
    

@marilion91 If the timestamp value is still up to date, I wonder if you have confirmed that the user is likely to be in the same location.

Please advise.

Kampai
  • 22,848
  • 21
  • 95
  • 95
  • why you want to get location every 5 seconds? don't you think it will consume unnecessary battery of user? – Ashwini Saini Jan 30 '20 at 08:11
  • @AshwiniViolet It is not a request every 5 seconds. The app asks for a location only when it is needed. A new request is made only if the time value of the last location has elapsed 5 seconds. but sometimes age value is returned as 0, new location requests are not made.Once it's 0, the value stays at 0. – Seulgi Lee Jan 30 '20 at 08:23
  • please provide the code of what you have done so far – Ashwini Saini Jan 30 '20 at 09:12
  • If you just want to check the last request time then i think best approach will be,just store/replace time on every successfully request using `System.currentTimeMillis()` and before request just put an If to compare newer one with previous(initial value will be 0). if difference is greater then 5 then do your request – Ashwini Saini Jan 30 '20 at 09:23

0 Answers0