Monday, August 22, 2011

[android-developers] Android location object time property stale ?

I'm trying to understand how to interpret the time property from the Android location object  :http://developer.android.com/reference/android/location/Location.html#getTime()

Here's the thing, when I call the location manager (using the GPS provider), I receive location fixes (I query them every 30 seconds) where the timestamp included in the location object almost always corresponds to the timestamp when the locationlistener got called.

14:20:00 - gps fix - android location timestamp 14:20:00
14:20:30 - gps fix - android location timestamp 14:20:30
14:21:00 - gps fix - android location timestamp 14:21:00

However, if I then switch to the WiFi provider, sometimes (not always) the timestamps on the location object don't correspond to the time when the locationlistener got called.
For example here, after getting the GPS fixes, I get a location through the locationlistener that has a more stale timestamp.

14:21:30 - wifi fix - android location timestamp 14:20:15

How should I interpret the 14:20:15 timestamp on the locationobject that was received at 14:21:30 ? 
I would imagine that if I query the locationmanager, it would always provide me with a timestamp at the time the request was made. The JavaDoc also says that the time property returns the UTC time of this fix, in milliseconds since January 1, 1970.

To avoid confusing, I'm not using stuff like getLastKnownLocation, it's the location object coming in via the LocationListener.onLocationChanged (http://developer.android.com/reference/android/location/LocationListener.html#onLocationChanged(android.location.Location)).

As a developer, should I check if the timestamp is too far off the current time, and simply ignore it in that case ? And can I force it to return me a fresh location ? (this is all happening when the phone is connected to a Wifi base station that is properly registered at Google Location Services.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment