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 ->
|
||||||
|
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {
|
||||||
|
Timber.d("## LocationTracker. lastKnownLocation: $lastKnownLocation")
|
||||||
|
} else {
|
||||||
Timber.d("## LocationTracker. lastKnownLocation")
|
Timber.d("## LocationTracker. lastKnownLocation")
|
||||||
callback?.onLocationUpdate(lastKnownLocation.toLocationData())
|
}
|
||||||
|
onLocationChanged(lastKnownLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
locationManager.requestLocationUpdates(
|
locationManager.requestLocationUpdates(
|
||||||
|
@ -91,11 +97,22 @@ class LocationTracker @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
Timber.d("## LocationTracker. onLocationChanged")
|
Timber.d("## LocationTracker. onLocationChanged")
|
||||||
}
|
}
|
||||||
if (location.provider != LocationManager.GPS_PROVIDER && hasGpsProviderLocation) {
|
notifyLocation(location)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun notifyLocation(location: Location) {
|
||||||
|
when (location.provider) {
|
||||||
|
LocationManager.GPS_PROVIDER -> {
|
||||||
|
hasGpsProviderLocation = true
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
if (hasGpsProviderLocation) {
|
||||||
// Ignore this update
|
// Ignore this update
|
||||||
Timber.d("## LocationTracker. ignoring location from ${location.provider}, we have gps location")
|
Timber.d("## LocationTracker. ignoring location from ${location.provider}, we have gps location")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
callback?.onLocationUpdate(location.toLocationData())
|
callback?.onLocationUpdate(location.toLocationData())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue