Hunt
Hunt

Reputation: 8435

deviation in GPS coordinates

I am trying to fetch latest location update using GPS in my android app where a user has to CHECK IN at specific location when he enters and CHECK OUT when he leaves both are manual operations. if user resides within the specified radius (i.e.18 meters) he will get successful CHECK IN.

following are my settings.

// Milliseconds per second
private static final int MILLISECONDS_PER_SECOND = 1000;
    // Update frequency in seconds
public static final int UPDATE_INTERVAL_IN_SECONDS = 40;
    // Update frequency in milliseconds
private static final long UPDATE_INTERVAL =
            MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS;


 private static final int FASTEST_INTERVAL_IN_SECONDS = 40;


 mLocationRequest = LocationRequest.create();
 mLocationRequest.setPriority(
     LocationRequest.PRIORITY_HIGH_ACCURACY
  );



  mLocationRequest.setInterval(UPDATE_INTERVAL);

  mLocationRequest.setFastestInterval(FASTEST_INTERVAL);

the issue with this approach is as i am fetching the location after every 40 seconds if user is at one place we are still getting deviation of 5 meters away from his current location in coordinates and sometimes more then that which is not acceptable.

so is there a way where i can configure that location api only fetch location if user goes out of 18 meters or else it will keep showing same co-cordinates ,i tried but its not working.

            mLocationRequest.setSmallestDisplacement(18);

Upvotes: 0

Views: 332

Answers (1)

ahjohnston25
ahjohnston25

Reputation: 1975

LocationRequest objects return themselves with each method call, so you can chain them together. See if this fixes the problem you're having:

 mLocationRequest = LocationRequest.create()
      .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
      .setInterval(UPDATE_INTERVAL)
      .setFastestInterval(FASTEST_INTERVAL);

This way the changes are actually saved to your LocationRequest object.

Upvotes: 0

Related Questions