지금 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);
}
}