2017-05-18 1 views
1

나는 FusedLocationApi를 사용하여 사용자의 위치 업데이트를 얻은 안드로이드 앱을 가지고 있습니다.왜 안드로이드 FusedLocationApi 몇 밀리 초 기간 내에 동일한 위치를 방송?

다음은 시나리오입니다. 1. 앱이 백그라운드 일 때도 위치를 얻으려는 보류중인 의도를 정의하는 싱글 톤 감시자 클래스가 있습니다. 코드를 다음과 같은 : 내가 성공적으로 위치 서비스를 연결 한 경우

private PendingIntent pendingIntent; 
    private Watcher() { 
     Intent locationIntent = new Intent(context, Receiver.class); 
     pendingIntent = PendingIntent.getBroadcast(
        context, 007 /*requestcode*/, locationIntent, 
     PendingIntent.FLAG_UPDATE_CURRENT); 
    } 

그런 다음, 나는 위치 업데이트를 요청 : WakefulBroadcastReceiver를 확장 수신기 클래스는 위치 업데이트를 얻을 때마다

이제
LocationServices.FusedLocationApi. 
        requestLocationUpdates(googleApiClient, locationRequest, pendingIntent); 

는, 그것은 시작 Service.class. 서비스 클래스는 IntentService를 확장합니다. 다음은 코드입니다 :

@Override 
synchronized protected void onHandleIntent(final Intent intent) { 
if(LocationResult.hasResult(intent)) { 
    LocationResult locationResult= LocationResult.extractResult(intent); 
    Location location = locationResult.getLastLocation(); 
    printLocation(location); 
} 

그래서 제 질문은, 위의 단계 주어, 왜 onHandleIntent 5 밀리 초 이내에 LocationReceiver 여러 번에 의해 깨어됩니다 않습니다됩니다. 위도, 경도 및 정확도는 모두 동일합니다. 또한, 위치 정밀도가 BALANCED_POWER_ACCURACY이고 I는

setFastestInterval(5 seconds); and 
setInterval(1 minute); 

정의; 내 응용 프로그램에서

LocationServices.FusedLocationApi. 
        requestLocationUpdates(googleApiClient, locationRequest, pendingIntent); 

가 여러 번 호출됩니다 않습니다. 그러나 설명서에 따르면 : "동일한 (PendingIntent (equals (Object)로 정의 된) 이전에 등록 된 요청은이 요청으로 대체 될 것입니다." 그리고 동일한 pendingIntent 객체를 사용하여 requestLocationUpdates를 호출합니다.

미리 감사드립니다.

답변

0

안녕하세요 Kanika 귀하의 위치 요청 개체를 통과하기 전에 최소 변위를 설정할 수 있습니다 이것은 특정 최소 변위가있을 때만 업데이트를 얻는 데 도움이됩니다. 같은 방법으로 아래의 방법을 사용할 수 있습니다. 또한

setSmallestDisplacement(float smallestDisplacementMeters) 

참고로 API 참조 링크, https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest

+0

이봐 알록, 응답에 대한 감사합니다. 나는 그것을 시도하고 몇 milliseconds에있는 갱신을 아직도 얻었다 : 여기에서 로그는있다 : 1) 05-17 21 : 33 : 04.654 2303-3697 중요한 위치는으로 변경했다 : 37.37984540, -122.06425810; 2) 05-17 21 : 33 : 07.474 2303-3841/키 위치 변경 : 37.37984000, -122.06452450; 3) 05-17 21 : 33 : 15.794 2303-3866/주요 위치가 37.37984000, -122.06452450 – Kanika

+0

으로 변경되었습니다. 변위에 대한 더 큰 값을 100 또는 1000이라고 말하고 여전히 동일한 문제가 발생하는지 확인하십시오. – Alok

+0

시도해 보니, 여전히 동일합니다. 보류중인 항목이 충분히 빨리 대체되지 않는다고 생각하십니까? 내가 몇 milliseconds의 기간에 requestLocationUpdates()를 여러 번 호출하기 때문에? – Kanika