Why is locationmanager returning old location fixe

2019-02-17 11:44发布

问题:

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...

回答1:

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.