My app uses FusedLocationProviderClient
to track the user's location when the app is running or in the background and it's working fine. But there are a few devices where location is not that accurate and sometimes jumps back and forth. All required permissions are granted.
The funny part is when the user opens google maps or starts to share live location via WhatsApp, my app is getting more accurate locations, and that brings me think that something is wrong with my implementation.
Here is the code I'm using
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
private lateinit var locationRequest: LocationRequest
private lateinit var locationCallback: LocationCallback
fun startLocationTracking() {
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
locationRequest = LocationRequest.create().apply {
interval = 10000
fastestInterval = 5000
maxWaitTime = 12000
smallestDisplacement = 50f
priority = Priority.PRIORITY_HIGH_ACCURACY
}
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult) {
super.onLocationResult(locationResult)
val location = locationResult.lastLocation
Log.e(TAG,location.toString())
Log.e(TAG,location?.accuracy.toString())
// broadcast
...
}
}
try {
fusedLocationProviderClient.requestLocationUpdates(
locationRequest, locationCallback, Looper.getMainLooper())
} catch (unlikely: SecurityException) {
Log.e(TAG, "Location update ERROR: $unlikely")
}
}
Any thoughts/suggestions on this?