I'm trying to execute a piece of code each time within 10 meters, when I first run my app, it executes all the code inside onLocationChange, but after I move more than 10 meters it seems like the listener is not working anymore or the location is not updated, any clue on what it might be causing this issue?
@Override
public void onLocationChanged(Location location) {
Toast.makeText(Principal.this, "it moved: " + location.getLatitude() + "" + location.getLongitude(), Toast.LENGTH_SHORT).show();
Log.i(TAG, "onLocationChanged: "+location.getLatitude()+""+location.getLongitude());
getPlaceByTimer();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Toast.makeText(this, "connected", Toast.LENGTH_SHORT).show();
startLocationUpdate();
}
private void initLocationRequest() {
mLastLocationRequest = new LocationRequest();
mLastLocationRequest.setSmallestDisplacement(10);
mLastLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
private void startLocationUpdate() {
initLocationRequest();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLastLocationRequest, this);
}
FusedLocationApi
appears to be deprecated, but what I was reading is that its working too for versions of Google Play services, so I think there is no a problem there