【问题标题】:Even PRIORITY_HIGH_ACCURACY gives very low accuracy location updates甚至 PRIORITY_HIGH_ACCURACY 也提供了非常低准确度的位置更新
【发布时间】:2018-02-21 22:09:37
【问题描述】:

我正在使用 FusedLocationAPI 获取高精度位置更新(更新间隔为 2 秒,最快间隔为 5 秒)。它在大多数情况下都能正常工作。但是,有时它会给出 1200m 的精度。

我知道一开始它可能会发生。但是,我遇到的问题是,我在一段时间内得到了公平(~20m 精度)的更新,然后突然切换到~1200m 精度。

在 Fused API 中怎么会发生这种情况?

【问题讨论】:

    标签: android gps fusedlocationproviderapi android-fusedlocation google-location-services


    【解决方案1】:

    有时会发生。此外,错误的定位可能会连续 5 分钟到达。 为了尝试过滤此类坐标,我使用了Location Strategies 文章中描述的方法(请参阅维护当前最佳估计部分)。

    private static final int TWO_MINUTES = 1000 * 60 * 2;
    
    /** Determines whether one Location reading is better than the current Location fix
     * @param location  The new Location that you want to evaluate
     * @param currentBestLocation  The current Location fix, to which you want to compare the new one
     */
    protected boolean isBetterLocation(Location location, Location currentBestLocation) {
        if (currentBestLocation == null) {
            // A new location is always better than no location
            return true;
        }
    
        // Check whether the new location fix is newer or older
        long timeDelta = location.getTime() - currentBestLocation.getTime();
        boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
        boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
        boolean isNewer = timeDelta > 0;
    
        // If it's been more than two minutes since the current location, use the new location
        // because the user has likely moved
        if (isSignificantlyNewer) {
            return true;
            // If the new location is more than two minutes older, it must be worse
        } else if (isSignificantlyOlder) {
            return false;
        }
    
        // Check whether the new location fix is more or less accurate
        int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
        boolean isLessAccurate = accuracyDelta > 0;
        boolean isMoreAccurate = accuracyDelta < 0;
        boolean isSignificantlyLessAccurate = accuracyDelta > 200;
    
        // Check if the old and new location are from the same provider
        boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());
    
        // Determine location quality using a combination of timeliness and accuracy
        if (isMoreAccurate) {
            return true;
        } else if (isNewer && !isLessAccurate) {
            return true;
        } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
            return true;
        }
        return false;
    }
    
    /** Checks whether two providers are the same */
    private boolean isSameProvider(String provider1, String provider2) {
        if (provider1 == null) {
            return provider2 == null;
        }
        return provider1.equals(provider2);
    }
    

    它是为与标准 Android Location API 一起使用而设计的,但它可以工作。我只是对其进行了一些更正,因为所有修复程序都具有相同的提供程序。它允许我过滤大约 30% 的“坏”位置修复。

    【讨论】:

    • 谢谢@fishbone。但是,我真正想要的是不断跟踪用户的最佳位置,因为我需要跟踪距离。在这种情况下,保持最佳修复并没有真正的帮助。在这种情况下,我切换到计步器读数来跟踪距离并且它可以工作。即使那样,如果这种巨大的不准确性一直持续到最后,我也无法弄清楚用户的最后一个位置是什么。特别是当它像你提到的那样持续发生几分钟时。
    【解决方案2】:

    原始 GPS 数据上的距离测量总是有噪音,因为基础数据通常不准确。这些跳跃是由于位置测量不准确造成的。要实现准确的距离测量,您可能需要过滤数据中的噪声。

    您可以探索的一些有用的过滤技术是:

    1. 使用卡尔曼滤波器平滑位置数据 - 请参阅 tutorial
    2. 使用 Google 地图snap-to-roads APIOSRM match service 捕捉道路。

    如果您正在寻找能够提供准确位置数据和距离测量的端到端解决方案,您也可以尝试适用于 Android 或 iOS 的 HyperTrack SDK。您可以在 their blog 上了解他们如何过滤位置以提高准确性。

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 1970-01-01
      • 2012-04-13
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多