1

我使用FusedLocationAPI獲取高精確度位置更新(具有2秒的更新間隔和5秒的最快間隔)。大多數時候它都能正常工作。但是,有時它會提供1200m的精度。即使PRIORITY_HIGH_ACCURACY給出的位置更新精度也很低

我明白,在一開始就可能發生。但是,我遇到的問題是,我得到公平(〜20m準確度)的更新一段時間,然後突然切換到〜1200m的準確度。

Fused API中如何發生這種情況?

回答

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位置API一起使用,但它的工作原理。我只是對它進行了一些更正,因爲所有修補程序都有相同的提供程序。它允許我過濾大約30%的「壞」位置修復。

+0

謝謝@fishbone。但是,我真正想要的是不斷跟蹤用戶的最佳位置,因爲我需要跟蹤距離。在這種情況下維護最佳修復方法並不能真正幫助您。在這種情況下,我切換到計步器讀數來跟蹤距離,它的工作原理。即使如此,如果這種巨大的不準確導致到最後,我無法弄清楚用戶的最後位置是什麼。特別是當它像你所說的那樣持續發生幾分鐘。 – wgihan

0

原始GPS數據的距離測量始終是嘈雜的,因爲底層數據往往不準確。這些跳躍是由於不準確的位置測量。要實現精確的距離測量,您可能需要過濾數據中的噪音。

,你可以探索

一些有用的過濾技術主要有:

  1. 利用卡爾曼濾波器平滑位置數據 - 見tutorial
  2. 捕捉到的道路與谷歌地圖snap-to-roads API,或OSRM match service

如果您正在尋找能夠提供準確位置數據和距離測量的端到端解決方案,您還可以嘗試Android或iOS的HyperTrack SDK。您可以閱讀他們如何過濾位置以提高their blog的準確性。 (聲明:我工作在HyperTrack。)

+0

謝謝@Aman Jain,這非常有幫助。 – wgihan

相關問題