Damir
Damir

Reputation: 56229

How to check if location which I got with GPS_PROVIDER or NETWORK_PROVIDER younger than 60 seconds ?

How to check if location which I got with GPS_PROVIDER or NETWORK_PROVIDER younger than 60 seconds ? I know to get location.getTime() in ms but I cannot compare that with System.currentTimeMillis() because different timezones. Is there any way to do this ?

Upvotes: 1

Views: 214

Answers (2)

Anish
Anish

Reputation: 166

I've implemented this and my approach was to copy the System.currentTimeMillis() into some double variable in the onLocationChanged() method of LocationListener. that way you get the time exactly when you get a new location. Moreover, you can compare this variable to the same System.currentTimeMillis() whenever you need to do so.

i know it's been a while this question is posted but, hoping it might help someone searching for it.

Upvotes: 2

chops
chops

Reputation: 11

The Location class has include the method getTime(), you can get this value and compare whether it is younger than 60s. I think it will work for you.

Upvotes: 0

Related Questions