FusedLocationProvider maxWaitTime的行为不符合预期

时间:2017-09-19 22:44:04

标签: android fusedlocationproviderapi

我刚刚将我的位置跟踪代码转换为使用LocationCallback来利用批处理。但是,我发现的是,地点很少进行批量处理,整体报告率会从我的请求率降低。

首先,使用Interval = maxWaitTime = 2秒查看结果(是的,我真的希望每2秒进行一次位置修复以跟踪字段上的运行/短划线移动)。代码是:

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))
    ;

其中FITNESS_HIGH_FREQUENCY_SECS = 2秒。

我确实每2秒获得一次位置更新:

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

现在我转换为60秒的maxWaitTime并每5-10秒获取一次位置更新。你可以从Now结果中看到没有人被批量化。

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

我没有更改(或设置)smallestDisplacement参数。显然结果不动,因为我坐在我的办公桌前。

哦,这是我的回调:

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");
            }
        }
    }
};

任何帮助,更正或指示赞赏。

0 个答案:

没有答案
相关问题