app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java
private LocationChangeType isBetterLocation(Location location, Location currentBestLocation) {

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

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

        // 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;

        // Check if the old and new location are from the same provider
        boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());

        float[] results = new float[5];
        Location.distanceBetween(
                        currentBestLocation.getLatitude(),
                        currentBestLocation.getLongitude(),
                        location.getLatitude(),
                        location.getLongitude(),
                        results);

        // If it's been more than two minutes since the current location, use the new location
        // because the user has likely moved
        if (isSignificantlyNewer
                || isMoreAccurate
                || (isNewer && !isLessAccurate)
                || (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) {
            if (results[0] < 1000) { // Means change is smaller than 1000 meter
                return LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
            } else {
                return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
            }
        } else{
            return LocationChangeType.LOCATION_NOT_CHANGED;
        }
    }
/**
     * Returns whether a given location is better than the current best location.
     *
     * @param location            the location to be tested
     * @param currentBestLocation the current best location
     * @return LOCATION_SIGNIFICANTLY_CHANGED if location changed significantly
     * LOCATION_SLIGHTLY_CHANGED if location changed slightly
     */
Returns whether a given location is better than the current best location.
@param location            the location to be tested
@param currentBestLocation the current best location
@return LOCATION_SIGNIFICANTLY_CHANGED if location changed significantly
LOCATION_SLIGHTLY_CHANGED if location changed slightly
Returns whether a given location is better than the current best location . @param location the location to be tested @param currentBestLocation the current best location @return LOCATION_SIGNIFICANTLY_CHANGED if location changed significantly LOCATION_SLIGHTLY_CHANGED if location changed slightly
private LocationChangeType isBetterLocation(Location location, Location currentBestLocation) {
        if (currentBestLocation == null) {
            return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
        }
        long timeDelta = location.getTime() - currentBestLocation.getTime();
        boolean isSignificantlyNewer = timeDelta > MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS;
        boolean isSignificantlyOlder = timeDelta < -MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS;
        boolean isNewer = timeDelta > 0;
        int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
        boolean isLessAccurate = accuracyDelta > 0;
        boolean isMoreAccurate = accuracyDelta < 0;
        boolean isSignificantlyLessAccurate = accuracyDelta > 200;
        boolean isFromSameProvider = isSameProvider(location.getProvider(),
                currentBestLocation.getProvider());
        float[] results = new float[5];
        Location.distanceBetween(
                        currentBestLocation.getLatitude(),
                        currentBestLocation.getLongitude(),
                        location.getLatitude(),
                        location.getLongitude(),
                        results);
        if (isSignificantlyNewer
                || isMoreAccurate
                || (isNewer && !isLessAccurate)
                || (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) {
            if (results[0] < 1000) { 
                return LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
            } else {
                return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
            }
        } else{
            return LocationChangeType.LOCATION_NOT_CHANGED;
        }
    }
private LocationChangeType isBetterLocation ( Location location , Location currentBestLocation ) { if ( currentBestLocation == null ) { return LocationChangeType . LOCATION_SIGNIFICANTLY_CHANGED ; } long timeDelta = location . getTime ( ) - currentBestLocation . getTime ( ) ; boolean isSignificantlyNewer = timeDelta > MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS ; boolean isSignificantlyOlder = timeDelta < - MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS ; boolean isNewer = timeDelta > 0 ; int accuracyDelta = ( int ) ( location . getAccuracy ( ) - currentBestLocation . getAccuracy ( ) ) ; boolean isLessAccurate = accuracyDelta > 0 ; boolean isMoreAccurate = accuracyDelta < 0 ; boolean isSignificantlyLessAccurate = accuracyDelta > 200 ; boolean isFromSameProvider = isSameProvider ( location . getProvider ( ) , currentBestLocation . getProvider ( ) ) ; float [ ] results = new float [ 5 ] ; Location . distanceBetween ( currentBestLocation . getLatitude ( ) , currentBestLocation . getLongitude ( ) , location . getLatitude ( ) , location . getLongitude ( ) , results ) ; if ( isSignificantlyNewer || isMoreAccurate || ( isNewer && ! isLessAccurate ) || ( isNewer && ! isSignificantlyLessAccurate && isFromSameProvider ) ) { if ( results [ 0 ] < 1000 ) { return LocationChangeType . LOCATION_SLIGHTLY_CHANGED ; } else { return LocationChangeType . LOCATION_SIGNIFICANTLY_CHANGED ; } } else { return LocationChangeType . LOCATION_NOT_CHANGED ; } }
Returns whether a given location is better than the current best location.
Returns whether a given location is better than the current best location .
// A new location is always better than no location // Check whether the new location fix is newer or older // Check whether the new location fix is more or less accurate // Check if the old and new location are from the same provider // If it's been more than two minutes since the current location, use the new location // because the user has likely moved // Means change is smaller than 1000 meter