【问题标题】:Android GPS returning same location coordinates with different accuracyAndroid GPS以不同的精度返回相同的位置坐标
【发布时间】:2018-09-02 01:40:57
【问题描述】:

我的应用程序使用ReactiveLocationProvider 使用LocationRequest 对象获取位置更新。完整代码如下:

mLocationRequestPassive = LocationRequest.create();
mLocationRequestPassive.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);     
mLocationRequestPassive.setFastestInterval(60000);     
mLocationRequestPassive.setInterval(PASSIVE_UPDATE_PERIOD_IN_SECONDS * 1000);
mSubscriptions.add(mReactiveLocationProviderPassive
                           .getUpdatedLocation(mLocationRequestPassive)
                           .observeOn(AndroidSchedulers.mainThread())
                           .subscribe(this::onLocationChanged,
                                      throwable -> Timber.w(throwable,
                                                   "Location request error")));

它几乎可以工作 95% 的时间,但有时它会开始发送重复的 lat/lng。但是,准确度是不同的。它曾经发生在其他人身上吗?有什么解决办法吗?

我正在使用以下版本的库

  • compile 'pl.charmas.android:android-reactive-location:0.9@aar'
  • compile 'com.google.android.gms:play-services-location:11.0.4'

更新

在此期间车辆正在移动。因此,添加 setSmallestDisplacement 只是将其从具有相同 lat/lng 的位置更新更改为没有位置更新。

【问题讨论】:

标签: android gps rx-java reactive-programming android-location


【解决方案1】:

不知道为什么会在服务中出现,但是一般情况下,你可以使用distinctUntilChanged(BiPredicate)来过滤掉后续项中的小改动:

Observable.just(10.0, 10.1, 10.15, 10.162, 11.0)
.distinctUntilChanged((prev, curr) -> Math.abs(prev - curr) < 0.09)
.subscribe(System.out::println);

【讨论】:

    猜你喜欢
    • 2013-01-20
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多