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
|
locationManager.allProviders
|
||||||
.takeIf { it.isNotEmpty() }
|
.takeIf { it.isNotEmpty() }
|
||||||
|
// Take GPS first
|
||||||
|
?.sortedByDescending { if (it == LocationManager.GPS_PROVIDER) 1 else 0 }
|
||||||
?.forEach { provider ->
|
?.forEach { provider ->
|
||||||
Timber.d("## LocationTracker. track location using $provider")
|
Timber.d("## LocationTracker. track location using $provider")
|
||||||
|
|
||||||
// Send last known location without waiting location updates
|
// Send last known location without waiting location updates
|
||||||
locationManager.getLastKnownLocation(provider)?.let { lastKnownLocation ->
|
locationManager.getLastKnownLocation(provider)?.let { lastKnownLocation ->
|
||||||
Timber.d("## LocationTracker. lastKnownLocation")
|
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {
|
||||||
callback?.onLocationUpdate(lastKnownLocation.toLocationData())
|
Timber.d("## LocationTracker. lastKnownLocation: $lastKnownLocation")
|
||||||
|
} else {
|
||||||
|
Timber.d("## LocationTracker. lastKnownLocation")
|
||||||
|
}
|
||||||
|
onLocationChanged(lastKnownLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
locationManager.requestLocationUpdates(
|
locationManager.requestLocationUpdates(
|
||||||
|
@ -91,10 +97,21 @@ class LocationTracker @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
Timber.d("## LocationTracker. onLocationChanged")
|
Timber.d("## LocationTracker. onLocationChanged")
|
||||||
}
|
}
|
||||||
if (location.provider != LocationManager.GPS_PROVIDER && hasGpsProviderLocation) {
|
notifyLocation(location)
|
||||||
// Ignore this update
|
}
|
||||||
Timber.d("## LocationTracker. ignoring location from ${location.provider}, we have gps location")
|
|
||||||
return
|
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())
|
callback?.onLocationUpdate(location.toLocationData())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue