FusedLocationProvider maxWaitTime not behaving as expected

Viewed 440

I just converted my Location tracking code to use LocationCallback to take advantage of the batching. However, what I'm finding is that locations are rarely batched, and that the overall reporting rate is reduced from my request rate.

First, look at the results with Interval = maxWaitTime = 2 seconds (yes, I really want location fixes every 2 seconds to track running/sprinting movement on a field). Code is:

mExactLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)  //10-foot accuracy
            .setInterval(TimeUnit.SECONDS.toMillis(FITNESS_HIGH_FREQUENCY_SECS))
            .setFastestInterval(TimeUnit.SECONDS.toMillis(FITNESS_FASTEST_INTERVAL_SECS))
            //TODO: Doesn't seem to work - don't get batching
            .setMaxWaitTime(TimeUnit.SECONDS.toMillis(FITNESS_HIGH_FREQUENCY_SECS))
    ;

where FITNESS_HIGH_FREQUENCY_SECS = 2 seconds.

I indeed get location updates every 2 seconds:

09-19 15:26:39.134 V: onLocationResult (Exact): Now 1505859999133, Fix time 1505859999000; Lat 37.283719, Long -122.024321, Alt 59.000000, Accuracy 25.789000
09-19 15:26:41.169 V: onLocationResult (Exact): Now 1505860001169, Fix time 1505860001000; Lat 37.283719, Long -122.024321, Alt 59.000000, Accuracy 24.271999
09-19 15:26:43.197 V: onLocationResult (Exact): Now 1505860003197, Fix time 1505860003000; Lat 37.283719, Long -122.024321, Alt 59.000000, Accuracy 25.789000
09-19 15:26:45.124 V: onLocationResult (Exact): Now 1505860005124, Fix time 1505860005000; Lat 37.283719, Long -122.024321, Alt 59.000000, Accuracy 24.271999
09-19 15:26:47.093 V: onLocationResult (Exact): Now 1505860007093, Fix time 1505860007000; Lat 37.283719, Long -122.024321, Alt 59.000000, Accuracy 24.271999
09-19 15:26:49.151 V: onLocationResult (Exact): Now 1505860009151, Fix time 1505860009000; Lat 37.283719, Long -122.024321, Alt 59.000000, Accuracy 24.271999

Now I convert to maxWaitTime of 60 seconds and get location update every 5-10 seconds. And you can see from the Now result that none are batched.

09-19 15:37:17.467 V: onLocationResult (Exact): Now 1505860637467, Fix time 1505860638339; Lat 37.283773, Long -122.024353, Alt 64.000000, Accuracy 7.585000
09-19 15:37:27.450 V: onLocationResult (Exact): Now 1505860647450, Fix time 1505860648398; Lat 37.283773, Long -122.024353, Alt 64.000000, Accuracy 7.585000
09-19 15:37:32.466 V: onLocationResult (Exact): Now 1505860652465, Fix time 1505860653431; Lat 37.283773, Long -122.024353, Alt 64.000000, Accuracy 7.585000
09-19 15:37:42.574 V: onLocationResult (Exact): Now 1505860662573, Fix time 1505860663484; Lat 37.283773, Long -122.024353, Alt 64.000000, Accuracy 7.585000
09-19 15:37:47.463 V: onLocationResult (Exact): Now 1505860667462, Fix time 1505860668511; Lat 37.283773, Long -122.024353, Alt 64.000000, Accuracy 7.585000

I am not changing (or setting) the smallestDisplacement parameter. Obviously the results don't move because I'm sitting at my desk.

Oh, here's my callback:

mExactLocationCallback = new LocationCallback() {
    @Override
    public void onLocationResult(LocationResult locationResult) {
        final long now = System.currentTimeMillis();
        for (Location location : locationResult.getLocations()) {
            if (location != null) {
                Log.v(TAG, String.format("onLocationResult (Exact): Now %d, Fix time %d; Lat %f, Long %f, Alt %f, Accuracy %f",
                        now, location.getTime(),
                        location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()));
                if (mSortedLocationList != null) mSortedLocationList.add(location);
            } else {
                Log.v(TAG, "onLocationResult(Exact) called with null location");
            }
        }
    }
};

Any help, corrections or pointers appreciated.

0 Answers
Related