0

I am using fusedlocationproviderapi in my Android app to transmit the users location. This works fine except sometimes the location jumps to a location in town and later shows that same location. I believe that the app switches from GPS to cell tower trialulation and in our area this does not work well.(MN) I use

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

in the manifest file and I would be fine with a way to ignore the faulty locations or detect those and not transmit those.

mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(UpdateSeconds * 1000);
    mLocationRequest.setFastestInterval(UpdateSeconds * 1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

I use the above code which works pretty good when I get a GPS location.

Azkik
  • 75
  • 4
  • 13

2 Answers2

1

If you're only interested in data coming from GPS, you can just use LocationManager with GPS_PROVIDER. I don't think of any benefit of using FusedLocationProviderApi if you're only interested in GPS.

Kazuki
  • 1,462
  • 14
  • 34
1

You can decide for every Location update if the new Location is "better" than the current best location. This avoids jumping out of your required accuracy:

protected boolean isBetterLocation(Location location,
        Location currentBestLocation) {
    final int TWO_MINUTES = 1000 * 60 * 2;

    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
    boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use
    // the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
        // If the new location is more than two minutes older, it must be
        // worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation
            .getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Determine location quality using a combination of timeliness and
    // accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate) {
        return true;
    }
    return false;
}
Chilly Code
  • 678
  • 2
  • 6
  • 17
  • Thank you. I went back to using Location Manager. I may try this if I have to use FusedLocationProviderApi in the future – Azkik May 24 '15 at 23:52