mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Add new location change states
This commit is contained in:
parent
7e999cb364
commit
581483e4ca
1 changed files with 32 additions and 29 deletions
|
|
@ -94,10 +94,10 @@ public class LocationServiceManager implements LocationListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
|
protected LocationChangeType isBetterLocation(Location location, Location currentBestLocation) {
|
||||||
if (currentBestLocation == null) {
|
if (currentBestLocation == null) {
|
||||||
// A new location is always better than no location
|
// A new location is always better than no location
|
||||||
return true;
|
return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the new location fix is newer or older
|
// Check whether the new location fix is newer or older
|
||||||
|
|
@ -106,15 +106,6 @@ public class LocationServiceManager implements LocationListener {
|
||||||
boolean isSignificantlyOlder = timeDelta < -MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS;
|
boolean isSignificantlyOlder = timeDelta < -MIN_LOCATION_UPDATE_REQUEST_TIME_IN_MILLIS;
|
||||||
boolean isNewer = timeDelta > 0;
|
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
|
// Check whether the new location fix is more or less accurate
|
||||||
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
|
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
|
||||||
boolean isLessAccurate = accuracyDelta > 0;
|
boolean isLessAccurate = accuracyDelta > 0;
|
||||||
|
|
@ -125,25 +116,31 @@ public class LocationServiceManager implements LocationListener {
|
||||||
boolean isFromSameProvider = isSameProvider(location.getProvider(),
|
boolean isFromSameProvider = isSameProvider(location.getProvider(),
|
||||||
currentBestLocation.getProvider());
|
currentBestLocation.getProvider());
|
||||||
|
|
||||||
float[] results = new float[5];
|
float[] results = new float[5];
|
||||||
Location.distanceBetween(
|
Location.distanceBetween(
|
||||||
currentBestLocation.getLatitude(),
|
currentBestLocation.getLatitude(),
|
||||||
currentBestLocation.getLongitude(),
|
currentBestLocation.getLongitude(),
|
||||||
location.getLatitude(),
|
location.getLatitude(),
|
||||||
location.getLongitude(),
|
location.getLongitude(),
|
||||||
results);
|
results);
|
||||||
|
|
||||||
if (isSignificantlyNewer
|
// If it's been more than two minutes since the current location, use the new location
|
||||||
|| isMoreAccurate
|
// because the user has likely moved
|
||||||
|| (isNewer && !isLessAccurate)
|
if (isSignificantlyNewer
|
||||||
|| (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) {
|
|| isMoreAccurate
|
||||||
Log.d("deneme","distance:"+results[0]);
|
|| (isNewer && !isLessAccurate)
|
||||||
return true;
|
|| (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) {
|
||||||
// If the new location is more than two minutes older, it must be worse
|
Log.d("deneme","distance:"+results[0]);
|
||||||
} else{
|
if (results[0] < 1000) { // Means change is smaller than 1000 meter
|
||||||
Log.d("deneme","distance:"+results[0]);
|
return LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
|
||||||
return false;
|
} else {
|
||||||
}
|
return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||||
|
}
|
||||||
|
// If the new location is more than two minutes older, it must be worse
|
||||||
|
} else{
|
||||||
|
Log.d("deneme","distance:"+results[0]);
|
||||||
|
return LocationChangeType.LOCATION_NOT_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,4 +203,10 @@ public class LocationServiceManager implements LocationListener {
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
Timber.d("Provider %s disabled", provider);
|
Timber.d("Provider %s disabled", provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum LocationChangeType{
|
||||||
|
LOCATION_SIGNIFICANTLY_CHANGED,
|
||||||
|
LOCATION_SLIGHTLY_CHANGED,
|
||||||
|
LOCATION_NOT_CHANGED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue