1

I have a location-aware Android app that uses the FusedLocationApi for location management.

When the app needs to get its location, it first fetches the last known location. If the location is not older than a minute, it uses that, otherwise it waits for a new location update.

Now, when moving around, say from location A to B, I observe the following behavior. Once I get to B, the app reports the location for B, which is great, and is the expected behavior. However, sometimes, the app will shortly thereafter report the location for A. How can this be, given that it already updated the current location to B?

Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
Gitahi Ng'ang'a
  • 901
  • 3
  • 10
  • 23

3 Answers3

0

When you reached to B it should show the last location as "B" But make sure u update your location frequently here u can set Location request.

LocationRequest locationRequest locationRequest = new LocationRequest();
        locationRequest.setInterval("4000"); //Interval 
        locationRequest.setFastestInterval("4000");//Fast Interval
        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Mohit Kacha
  • 484
  • 2
  • 12
0

The class Location which is the result of FusedLocationAPI has a getTime() function. When you receive a Location update, you can use the getTime function to compare with the previous one to see which one is more recent.

Viven
  • 627
  • 7
  • 14
0

Make sure you use these parameters wisely. As it impacts battery and app performance.

//update interval
setInterval(UPDATE_INTERVAL);
//Fastest interval
setFastestInterval(FASTEST_INTERVAL);
//Accuracy required
setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
//Smallest variation in between locations
setSmallestDisplacement(MIN_DISTANCE_CHANGE_FOR_UPDATES);

As you may not have set setSmallestDisplacement , it may causes same old location to be retrieved back.

Sreehari
  • 5,621
  • 2
  • 25
  • 59