network "not live" lcoation can be more accurate than GPS "not live" location. So do not ignore them. Not sure how if this is a universal rule...

This commit is contained in:
Benoit Marty 2022-01-31 12:47:17 +01:00
parent 2fbb434099
commit ecd41d3826

View File

@ -40,12 +40,12 @@ class LocationTracker @Inject constructor(
private var callback: Callback? = null private var callback: Callback? = null
private var hasGpsProviderLocation = false private var hasGpsProviderLiveLocation = false
@RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION]) @RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])
fun start(callback: Callback?) { fun start(callback: Callback?) {
Timber.d("## LocationTracker. start()") Timber.d("## LocationTracker. start()")
hasGpsProviderLocation = false hasGpsProviderLiveLocation = false
this.callback = callback this.callback = callback
if (locationManager == null) { if (locationManager == null) {
@ -66,9 +66,9 @@ class LocationTracker @Inject constructor(
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {
Timber.d("## LocationTracker. lastKnownLocation: $lastKnownLocation") Timber.d("## LocationTracker. lastKnownLocation: $lastKnownLocation")
} else { } else {
Timber.d("## LocationTracker. lastKnownLocation") Timber.d("## LocationTracker. lastKnownLocation: ${lastKnownLocation.provider}")
} }
onLocationChanged(lastKnownLocation) notifyLocation(lastKnownLocation, isLive = false)
} }
locationManager.requestLocationUpdates( locationManager.requestLocationUpdates(
@ -95,20 +95,20 @@ class LocationTracker @Inject constructor(
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {
Timber.d("## LocationTracker. onLocationChanged: $location") Timber.d("## LocationTracker. onLocationChanged: $location")
} else { } else {
Timber.d("## LocationTracker. onLocationChanged") Timber.d("## LocationTracker. onLocationChanged: ${location.provider}")
} }
notifyLocation(location) notifyLocation(location, isLive = true)
} }
private fun notifyLocation(location: Location) { private fun notifyLocation(location: Location, isLive: Boolean) {
when (location.provider) { when (location.provider) {
LocationManager.GPS_PROVIDER -> { LocationManager.GPS_PROVIDER -> {
hasGpsProviderLocation = true hasGpsProviderLiveLocation = isLive
} }
else -> { else -> {
if (hasGpsProviderLocation) { if (hasGpsProviderLiveLocation) {
// 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 live location")
return return
} }
} }