1

I am facing an issue with the data provided from GPS.

I am calculating the distance upon the location change callback, so when the device is idle the distance getting incremented due to the GPS fluctuation.

I have been using FusedLocationProviderClient for getting the location update.

 fusedLocationClient.requestLocationUpdates(locationRequest,
                   locationCallback, Looper.myLooper()); 




fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
            mLocationCallback = new LocationCallback() {
                @Override
                public void onLocationResult(LocationResult locationResult) {
                    super.onLocationResult(locationResult);
                    onNewLocation(locationResult.getLastLocation());
                }
            };


 private void createLocationRequest() {
    locationRequest = new LocationRequest();
    locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
    locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
Rissmon Suresh
  • 13,173
  • 5
  • 29
  • 38
  • try to use high accuracy `mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)` – Saveen Jan 10 '18 at 10:09
  • take a reference from here https://stackoverflow.com/questions/39314901/getting-latitude-and-longitude-in-30-seconds/39315097#39315097 – Saveen Jan 10 '18 at 10:10
  • @Saveen already it's "LocationRequest.PRIORITY_HIGH_A‌​ACCURACY" i have given. – Rissmon Suresh Jan 10 '18 at 10:25

2 Answers2

2

The positioning accuracy of GPS is not better than 4 or 5 meters. that is, each time a position is calculated it can be within a radius never less than about 4 meters. Some time the calculated position will be displaced meters to the front, sometimes to the left, back, etc.

If you want those small variations not to be taken into account, it must be your code that discriminates if the user has really moved.

It sounds difficult, yes, but this is the merit for an application or GPS device to calculate near to correct distances.

from56
  • 3,976
  • 2
  • 13
  • 23
  • How do we know if the user has really moved? – Rissmon Suresh Jan 10 '18 at 11:15
  • Can we do it checking the distance change or by the some sensors?? – Rissmon Suresh Jan 10 '18 at 11:16
  • 1
    How do we know if the user has really moved?: that's the question of the million dollars ! hehe, I only know that devices such as Garmin use very complicated algorithms. Sensors ? The accelerations of a person walking are so weak that I think almost impossible to be useful, also the accuracy of the sensors of a mobile phone is low. – from56 Jan 10 '18 at 11:23
1

Lluis Felisart is correct. There are random-seeming fluctuations in the Locations reported in the callback.

One simple thing you can try is, in your LocationCallback check LocationResult.getLocations() where the last two elements will be the two most recent Locations you've received. For these two Locations, compare the sum of their getAccuracy() values, times some fudge factor K, with the distance between these same two Locations. If the resulting accuracy is less than the distance between the locations, ignore the location update. This is definitely not perfect but will filter out some noise.

Perhaps a more advanced approach that may work better is to compute a weighted moving average of Locations in LocationResult.getLocations(). You can weight each Location by its getAccuracy() value.

vlazzle
  • 811
  • 9
  • 14