6

We have an app that upon user action tries to get a location fix. It listens both on GPS and network and has a time/accuracy based decision matrix to determine when to stop listening and what fix to return.

We have noticed, on occasion, a very strange behaviour. We use the classic way to see how old the fix is, like so:

long age = now - newLocation.getTime();
if(age >= prefs.getLocationMaxAge()){
    Log.d(TAG, "location too old.");
    return;
}

But sometimes, the location.getTime returned from the OS has an age of perhaps 15-20 seconds, according to the returned timestamp, although we can tell for certain that it's very old. For example, if the longitude/latitude fix is from a position that the handset was on 30 minutes ago!

It seems to happen both from Wi-Fi and network, but not GPS. To me, this is totally crazy. Has anyone else seen this and is there any way around it?

We have gotten it on a couple of different phones, most recent one is Samsung Galaxy S II.

Help would be extremely welcome.

EDIT: To be really clear, the problem is that the "onlocationchanged" callback gets called by the OS with a location with a timestamp age of perhaps a couple of seconds, when I know for certain that the longitude/latitude in the "new" fix is a place where the phone hasn't been at for at least 30 minutes.

This makes it kind of hard to accurately determine where the handset it...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mathias
  • 3,879
  • 5
  • 36
  • 48

1 Answers1

0

It seems to happen both from Wi-Fi and network, but not GPS

This seems fair, because in the Wi-Fi and network cell-site based triangulation, the accuracy is very bad. They are probably using cached locations which date back to 30 minutes ago. Unless you have not changed your cell-site or moved to another building so that new APs can be discovered, I'm afraid you will get only cached locations. If you want fresh locations use the GPS provider.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Reno
  • 33,594
  • 11
  • 89
  • 102
  • 1
    I think you are missing my point. Cached locations would be fine, if the timestamp of the location would reflect this. But taking a cached, old fix, and applying a current timestamp is crazy. i will update my question to be even clearer. – Mathias Oct 04 '11 at 13:14
  • Thanks for clearing it up; I've found [the culprit](http://www.netmite.com/android/mydroid/frameworks/base/location/java/com/android/internal/location/LocationCollector.java) – Reno Oct 04 '11 at 14:19
  • HI guyz , relative to this i got location proper but when i try to find how old this location using ->> long age = System.currentTimeMillis() -location.getTime(); and depend on this value i calculate how my location is but the problem is sometime i got negative value (age). not able to understood why because that age will never comes in negative – Anjan Oct 28 '15 at 08:21