【问题标题】:Flutter Location Tracking IssuesFlutter 位置跟踪问题
【发布时间】:2019-09-25 09:50:27
【问题描述】:

我正在尝试在我的应用上使用实时 GPS 跟踪来跟踪用户的动作,但整个事情是如此不一致。我正在使用两个推荐的库来实现这一点。这是我正在使用的两个库:

这就是问题所在。两个库都返回坐标,但每当我静止不动时,GPS 坐标就会不断跳来跳去。我真的把我的手机放在桌子上,我会看到这两个图书馆每秒都会给我不同的坐标,即使我的手机已经死了。我会说坐标通常在 10 米半径内,但它绝对会影响我的核心应用程序功能,因为我至少需要准确性或一致性。我很可能错过了一些东西,如果可以的话,请有人帮忙。这是我使用这两个库的代码:

位置库:

var location = new Location();

        location.onLocationChanged().listen((LocationData currentLocation) {
          print("Coord: ${currentLocation.latitude} ${currentLocation.longitude}");
          _approachingGate
              .getApproachingGate(
                  Position(
                      latitude: currentLocation.latitude,
                      longitude: currentLocation.longitude),
                  _userGates,
                  distance: 0)
              .then((Map<String, Object> value) {
            _nearbyGate = value[Constants.GATE];
            notifyListeners();
          });
        });

地理定位库:

var geoLocator = Geolocator();
        var locationOptions = LocationOptions(
            accuracy: LocationAccuracy.bestForNavigation,);

        Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
        _approachingGate
            .getApproachingGate(position, _userGates,distance: 8)
            .then((Map<String, Object> value) {
          _nearbyGate = value[Constants.GATE];
          notifyListeners();

        });

        _positionStream = geoLocator
            .getPositionStream(locationOptions)
            .listen((Position position) {
              print("Coord: ${position.latitude} ${position.longitude}");
          _position = position;
          var x = 2.0;
          _approachingGate
              .getApproachingGate(position, _userGates,distance: x)
              .then((Map<String, Object> value) {
            _nearbyGate = value[Constants.GATE];

            notifyListeners();

          });

GeoLocator 库允许我使用distanceFilter 仅在移动一定距离后进行更新,并且出于某种原因,它仅在需要时才起作用。

这是我刚刚得到的一些输出,当时我正忙着打字,我的设备还在桌子上。

I/flutter ( 7705): Coord: -26.1010019 28.0388391
I/flutter ( 7705): Coord: -26.101002 28.0388395
I/flutter ( 7705): Coord: -26.1010019 28.0388403
I/flutter ( 7705): Coord: -26.1010018 28.0388407
I/flutter ( 7705): Coord: -26.1010018 28.0388393
I/flutter ( 7705): Coord: -26.1010026 28.0388364
I/flutter ( 7705): Coord: -26.1010022 28.0388392
I/flutter ( 7705): Coord: -26.101002 28.0388393
I/flutter ( 7705): Coord: -26.1010021 28.0388405
I/flutter ( 7705): Coord: -26.1010024 28.03884
I/flutter ( 7705): Coord: -26.1010025 28.038839
I/flutter ( 7705): Coord: -26.1010022 28.0388383
I/flutter ( 7705): Coord: -26.1010423 28.0388409
I/flutter ( 7705): Coord: -26.1010033 28.0388375

【问题讨论】:

  • 这是由于 GPS 卫星运动导致数据倾斜。任何没有这个问题的应用程序只是简单地对这些结果进行排序和平滑。例如,下次你去散步时,使用路线追踪器,并保持静止约 5 分钟。你可能会看到一团乱七八糟的东西。
  • @spongyboss 你找到解决这个位置问题的方法了吗?实际上,我也面临同样的问题。

标签: flutter dart geolocation location


【解决方案1】:

问题是你做得对。我的意思是,我用 Flutter Geolocator 做了很多工作(很少用 Location),我也遇到了同样的问题。我深入研究了 Android 的 API 和源代码。您可以在 Android 核心库(FusedLocationProviderClient 和 Location)的 javadoc 中找到解释。 例如,在此链接中,您可以看到 Android 本身返回的 GPS 位置的“准确度”为 68%(或多或少 1 个 sigma,具有高斯分布)。 javadoc 警告您:

我们将水平精度定义为 68% 置信度的半径。换句话说,如果您以该位置的纬度为中心画一个圆 和经度,半径等于精度,那么那里 真实位置在圆圈内的概率为 68%。

因此,您每次启动服务时都会生成数据,并且没有抽象库(如 Geolocator 或类似的东西)可以比 Android 做得更好或解决错误。 IO 应该更准确,但我主要使用 Android 工作,所以我几乎没有关于它的数据。 文档的两个链接:

地点:

https://developer.android.com/reference/android/location/Location#getAccuracy()

FusedLocationProviderClient:

https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient

我希望这会有所帮助, 问候。

【讨论】:

    猜你喜欢
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 2021-10-05
    • 2021-02-22
    • 1970-01-01
    相关资源
    最近更新 更多