即使PRIORITY_HIGH_ACCURACY给出的位置更新精度也很低

问题描述:

我使用FusedLocationAPI获取高精确度位置更新(具有2秒的更新间隔和5秒的最快间隔)。大多数时候它都能正常工作。但是,有时它会提供1200m的精度。即使PRIORITY_HIGH_ACCURACY给出的位置更新精度也很低

我明白,在一开始就可能发生。但是,我遇到的问题是,我得到公平(〜20m准确度)的更新一段时间,然后突然切换到〜1200m的准确度。

Fused API中如何发生这种情况?

有时会发生。而且,错误的定位可以连续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位置API一起使用,但它的工作原理。我只是对它进行了一些更正,因为所有修补程序都有相同的提供程序。它允许我过滤大约30%的“坏”位置修复。

+0

谢谢@fishbone。但是,我真正想要的是不断跟踪用户的最佳位置,因为我需要跟踪距离。在这种情况下维护最佳修复方法并不能真正帮助您。在这种情况下,我切换到计步器读数来跟踪距离,它的工作原理。即使如此,如果这种巨大的不准确导致到最后,我无法弄清楚用户的最后位置是什么。特别是当它像你所说的那样持续发生几分钟。 – wgihan

原始GPS数据的距离测量始终是嘈杂的,因为底层数据往往不准确。这些跳跃是由于不准确的位置测量。要实现精确的距离测量,您可能需要过滤数据中的噪音。

,你可以探索

一些有用的过滤技术主要有:

  1. 利用卡尔曼滤波器平滑位置数据 - 见tutorial
  2. 捕捉到的道路与谷歌地图snap-to-roads API,或OSRM match service

如果您正在寻找能够提供准确位置数据和距离测量的端到端解决方案,您还可以尝试Android或iOS的HyperTrack SDK。您可以阅读他们如何过滤位置以提高their blog的准确性。 (声明:我工作在HyperTrack。)

+0

谢谢@Aman Jain,这非常有帮助。 – wgihan