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.