마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

onLocationChanged 호출 시점..

0 추천

지금 intentService에서 위치정보를 가져오려고 합니다.

그런데 onLocationChanged 안에서 Log.i를 호출해보니 위치가 변하지 않더라도 약 1초에 한번씩 로그가 찍힙니다..제가 알기로는 onLocationChanged 함수는 위치의 변화가 있어야 호출이 되는 걸로 알고있는데 왜 이런거죠?

기기는 제니모션을 쓰고 있습니다.

소스코드입니다.

public class UserLocationService extends IntentService {
    LocationManager locationManager;
    LocationListener locationListener;
    PendingIntent pendingIntent;
    double latitude,longitude;
 
    public UserLocationService(){
        super("UserLocationService");
    }
 
    @Override
    public void onCreate() {
        super.onCreate();
        locationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
        Intent intent=new Intent(this, ConformLocation.class);
        pendingIntent= PendingIntent.getBroadcast(this, 0, intent, 0);
 
        locationListener=new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                latitude=location.getLatitude();
                longitude=location.getLongitude();
                Toast.makeText(getApplicationContext(),""+latitude+" "+longitude,Toast.LENGTH_SHORT).show();
                Log.i("onLocationChanged","onLocationChanged");
            }
 
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
 
            }
 
            @Override
            public void onProviderEnabled(String provider) {
 
            }
 
            @Override
            public void onProviderDisabled(String provider) {
 
            }
        };
 
        if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER))
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER))
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
 
 
    }
 
    @Override
    protected void onHandleIntent(Intent intent) {
        locationManager.addProximityAlert(37.5818,127.01,2000,-1,pendingIntent);
    }
}
빙구짱 (1,720 포인트) 님이 2015년 3월 11일 질문

1개의 답변

0 추천
 
채택된 답변
requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)
 
Register for location updates using the named provider, and a pending intent.
 
2, 3 번째 인자 확인하세요
aucd29 (218,390 포인트) 님이 2015년 3월 11일 답변
빙구짱님이 2015년 3월 11일 채택됨
감사합니다 최소거리가 0이니 계속 호출되네요 이거랑 관련있을 줄은...
...