0

I would like to locate the user by clicking on a button. Therefore I use this code:

lm = getSystemService(LocationManager.class);
provider = LocationManager.GPS_PROVIDER;
listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
   Log.e("UPDATE","UPDATING LOCATION");
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {

}
@Override
public void onProviderEnabled(String s) {

}
@Override
public void onProviderDisabled(String s) {

}
};

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);

The requestLocationUpdates method is called but the onLocationChanged method is only called a few times. GPS is activated and the permissions are granted.

Do you have any idea why onLocationChanged is not always called? I also checked getLastKnownLocation which is sometimes false after calling requestLocationUpdates.

JavaForAndroid
  • 1,111
  • 2
  • 20
  • 42

2 Answers2

0

I think onLocationChanged() is not suppose to be called always, it will only be called if a location changes.

Hohenheim
  • 393
  • 2
  • 16
0

I changed the request method to lm.requestSingleUpdate(criteria, listener,null); which works perfect as well as requestLocationUpdates with criteria.

Seems to be a problem with the provider.

JavaForAndroid
  • 1,111
  • 2
  • 20
  • 42