0

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" />                                                                                                                                                                                      
blackHawk
  • 6,047
  • 13
  • 57
  • 100

1 Answers1

0

Maybe you could check this one : Android map Update location to server when there is difference of x meters between current location and last location and see the difference of your distance when you moved, so you will know where the source of the over-movement occured.

Danee
  • 322
  • 1
  • 4
  • Is there differemce between last location and current location, because with fusedlocation.lastlocation we can know current location – blackHawk Jul 16 '17 at 10:59