I only want to get current location updates when I move atleast 3 meters from current location for this I used
FusedLocationClient.requestLocationUpdates
for this i made LocationRequest like this:
private LocationRequest requestLocation(){
LocationRequest mLocationRequest = new LocationRequest();
mLocationRequest.setSmallestDisplacement(3.81f);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
return mLocationRequest;
}
and implemented like this: after connected to play service
@Override
public void onConnected(Bundle bundle) {
mFusedLocationClient.requestLocationUpdates(requestLocation(),
new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (final Location location : locationResult.getLocations()) {
tvLat.setText(Double.toString(location.getLatitude()));
tvLng.setText(Double.toString(location.getLongitude()));
//changing position of marker and camera
changeCameraPosition(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()),
16), new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {}
@Override
public void onCancel() { }
});
}
}
}, Looper.myLooper());
but Im getting latlng from this atleast 650m far from my current location even if I didn't move slightest, here is my permissions in manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="permission.READ_GSERVICES" />