2011-10-24 13 views
1

ネットワークプロバイダを使用してAndroid上のユーザーの場所をトラッキングすると、セルがスリープ(サスペンド)モードになっているときに更新に非常に時間がかかります。この投稿の同じ問題: Android network location takes hours to update locationAndroidネットワークの場所(更新の時間)

私はAlarmManagerを使用して、PARTIAL_WAKE_LOCKでサービスを開始するインテントを起動し、リスナーから位置更新を受信して​​(ワockロックを解除する)まで待機します。

すべてが完全にGPSプロバイダを使用して動作します。すべての権限はOKです(細かい/粗い場所、ワコロック)。

ありがとうございました!この問題によって発生

EDIT 問題:http://code.google.com/p/android/issues/detail?id=10931

答えて

0

は、新しい場所を表示するために、より良いものであるかどうかを検証するために、任意のロジックを持っていますか?古い場所は、ある条件を満たすまで、常により良い場所とみなされるかもしれません。以下のスニペットを試してください:

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); 
} 
+0

はい、私はこれを確認です。しかし、この場合(ネットワークプロバイダ)私のリスナーは2〜3時間で解雇されません。私の悪い英語の言い訳。 – pcmarafon

+0

この問題の原因となる問題:http://code.google.com/p/android/issues/detail?id=10931 – pcmarafon

0

問題は、ネットワークプロバイダが非常に不正確であることです。 (およそ3kmの範囲で)ゆっくりと位置が更新されるので、あなたはあるセルサイトから別のサイトに移動する必要があります。

編集:それは結局のところ、これはa known issue

+0

私の家から20km離れたところを移動しています。 – pcmarafon

+0

奇妙なことですが、ネットワークプロバイダのコードはオープンソースではないので、実際にどのように動作するのかわかりません。 – Reno

+0

この問題による問題:http://code.google.com/p/android/issues/detail?id=10931 – pcmarafon

関連する問題