Avoid taking into account any provider location if we have gps location.
This commit is contained in:
parent
99f82d9691
commit
a8c251f6f5
|
@ -56,13 +56,19 @@ class LocationTracker @Inject constructor(
|
|||
|
||||
locationManager.allProviders
|
||||
.takeIf { it.isNotEmpty() }
|
||||
// Take GPS first
|
||||
?.sortedByDescending { if (it == LocationManager.GPS_PROVIDER) 1 else 0 }
|
||||
?.forEach { provider ->
|
||||
Timber.d("## LocationTracker. track location using $provider")
|
||||
|
||||
// Send last known location without waiting location updates
|
||||
locationManager.getLastKnownLocation(provider)?.let { lastKnownLocation ->
|
||||
Timber.d("## LocationTracker. lastKnownLocation")
|
||||
callback?.onLocationUpdate(lastKnownLocation.toLocationData())
|
||||
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {
|
||||
Timber.d("## LocationTracker. lastKnownLocation: $lastKnownLocation")
|
||||
} else {
|
||||
Timber.d("## LocationTracker. lastKnownLocation")
|
||||
}
|
||||
onLocationChanged(lastKnownLocation)
|
||||
}
|
||||
|
||||
locationManager.requestLocationUpdates(
|
||||
|
@ -91,10 +97,21 @@ class LocationTracker @Inject constructor(
|
|||
} else {
|
||||
Timber.d("## LocationTracker. onLocationChanged")
|
||||
}
|
||||
if (location.provider != LocationManager.GPS_PROVIDER && hasGpsProviderLocation) {
|
||||
// Ignore this update
|
||||
Timber.d("## LocationTracker. ignoring location from ${location.provider}, we have gps location")
|
||||
return
|
||||
notifyLocation(location)
|
||||
}
|
||||
|
||||
private fun notifyLocation(location: Location) {
|
||||
when (location.provider) {
|
||||
LocationManager.GPS_PROVIDER -> {
|
||||
hasGpsProviderLocation = true
|
||||
}
|
||||
else -> {
|
||||
if (hasGpsProviderLocation) {
|
||||
// Ignore this update
|
||||
Timber.d("## LocationTracker. ignoring location from ${location.provider}, we have gps location")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
callback?.onLocationUpdate(location.toLocationData())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue