diff --git a/app/src/main/java/org/y20k/trackbook/Keys.kt b/app/src/main/java/org/y20k/trackbook/Keys.kt index 30a3609..4ac8433 100644 --- a/app/src/main/java/org/y20k/trackbook/Keys.kt +++ b/app/src/main/java/org/y20k/trackbook/Keys.kt @@ -96,7 +96,7 @@ object Keys { const val ONE_HOUR_IN_MILLISECONDS: Int = 3600000 const val EMPTY_STRING_RESOURCE: Int = 0 const val REQUEST_CURRENT_LOCATION_INTERVAL: Long = 1000L // 1 second in milliseconds - const val ADD_WAYPOINT_TO_TRACK_INTERVAL: Long = 15000L // 15 seconds in milliseconds + const val ADD_WAYPOINT_TO_TRACK_INTERVAL: Long = 1000L // 1 second in milliseconds const val SIGNIFICANT_TIME_DIFFERENCE: Long = 120000L // 2 minutes in milliseconds const val STOP_OVER_THRESHOLD: Long = 300000L // 5 minutes in milliseconds const val IMPLAUSIBLE_TRACK_START_SPEED: Double = 250.0 // 250 km/h diff --git a/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.kt b/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.kt index 3a6584a..a0c61dc 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.kt +++ b/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.kt @@ -27,6 +27,7 @@ import androidx.core.content.ContextCompat import org.y20k.trackbook.Keys import org.y20k.trackbook.core.Track import java.util.* +import kotlin.math.pow /* @@ -179,17 +180,21 @@ object LocationHelper { fun isDifferentEnough(previousLocation: Location?, location: Location): Boolean { // check if previous location is (not) available if (previousLocation == null) return true - // check if distance between is large enough - val distanceThreshold: Float - val averageAccuracy: Float = (previousLocation.accuracy + location.accuracy) / 2 - // increase the distance threshold if one or both locations are - if (averageAccuracy > Keys.DEFAULT_THRESHOLD_DISTANCE) { - distanceThreshold = averageAccuracy - } else { - distanceThreshold = Keys.DEFAULT_THRESHOLD_DISTANCE - } - // location is different when far enough away from previous location - return calculateDistance(previousLocation, location) > distanceThreshold + + // location.accuracy is given as 1 standard deviation, with a 68% chance + // that the true position is within a circle of this radius. + // These formulas determine if the difference between the last point and + // new point is statistically significant. + val accuracy = if (location.accuracy != 0.0f) location.accuracy else Keys.DEFAULT_THRESHOLD_DISTANCE + val previousAccuracy = if (previousLocation.accuracy != 0.0f) previousLocation.accuracy else Keys.DEFAULT_THRESHOLD_DISTANCE + val accuracyDelta = Math.sqrt((accuracy.pow(2) + previousAccuracy.pow(2)).toDouble()) + + val distance = calculateDistance(previousLocation, location) + + // With 1*accuracyDelta we have 68% confidence that the points are + // different. We can multiply this number to increase confidence but + // decrease point recording frequency if needed. + return distance > accuracyDelta } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2048088..134ee30 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -76,7 +76,7 @@ About Version App Version - Discard location fixes with an accuracy larger than: + Discard location fixes with an accuracy larger than (meters): Accuracy Threshold Advanced Delete all recordings in \"Tracks\" that are not starred.