Skip to content

Commit

Permalink
Filter too inaccurate locations to avoid sending low quality data
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaakko committed Nov 22, 2023
1 parent dd73e9d commit 5726145
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class ScannerService : Service() {

private val LOCATION_MAX_AGE = 20.seconds

//Filter locations where accuracy is higher than 200 meters
private const val LOCATION_MAX_ACCURACY = 200

private var _serviceRunning = false
val serviceRunning: Boolean
get() = _serviceRunning
Expand Down Expand Up @@ -154,6 +157,10 @@ class ScannerService : Service() {
.filter {
(SystemClock.elapsedRealtimeNanos() - it.location.elapsedRealtimeNanos).nanoseconds < LOCATION_MAX_AGE
}
.filter {
//Filter too inaccurate locations to avoid sending low quality data to MLS
it.location.hasAccuracy() && it.location.accuracy <= LOCATION_MAX_ACCURACY
}
.runningFold<LocationWithSource, Pair<LocationWithSource?, LocationWithSource?>>(null to null) { pair, newLocation ->
pair.second to newLocation
}
Expand Down

0 comments on commit 5726145

Please sign in to comment.