2011-10-24 4 views
1

네트워크 제공 업체를 통해 Android에서 사용자 위치를 추적 할 때 셀이 절전 모드 일 때 업데이트에 대해 매우 긴 시간이 걸립니다. 이 게시물의 동일한 문제 : Android network location takes hours to update location.Android 네트워크 위치 (업데이트 시간)

AlarmManager를 사용하여 PARTIAL_WAKE_LOCK으로 서비스를 시작하는 인 텐트를 실행하고 리스너로부터 위치 업데이트를 수신 할 때까지 기다렸다가 자체 중지 (wakelock 해제)합니다.

GPS 제공 업체를 통해 완벽하게 작동합니다. 모든 권한은 괜찮습니다 (벌금/거친 위치, wakelock).

아이디어가 있으십니까? 고맙습니다! 이 문제로 인해 발생

편집 문제 : 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