Who told you that we don't use fused location provider? We use both.
In the tracar client code AndroidPositionProvider is only used
class AndroidPositionProvider(context: Context, listener: PositionListener) : PositionProvider(context, listener), LocationListener {
private val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
private val provider = getProvider(preferences.getString(MainFragment.KEY_ACCURACY, "medium"))
@SuppressLint("MissingPermission")
override fun startUpdates() {
try {
locationManager.requestLocationUpdates(
provider, if (distance > 0 || angle > 0) MINIMUM_INTERVAL else interval, 0f, this)
} catch (e: RuntimeException) {
listener.onPositionError(e)
}
}
override fun stopUpdates() {
locationManager.removeUpdates(this)
}
@Suppress("DEPRECATION", "MissingPermission")
override fun requestSingleLocation() {
try {
val location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER)
if (location != null) {
listener.onPositionUpdate(Position(deviceId, location, getBatteryStatus(context)))
} else {
locationManager.requestSingleUpdate(provider, object : LocationListener {
override fun onLocationChanged(location: Location) {
listener.onPositionUpdate(Position(deviceId, location, getBatteryStatus(context)))
}
override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {}
override fun onProviderEnabled(provider: String) {}
override fun onProviderDisabled(provider: String) {}
}, Looper.myLooper())
}
} catch (e: RuntimeException) {
listener.onPositionError(e)
}
}
override fun onLocationChanged(location: Location) {
processLocation(location)
}
override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {}
override fun onProviderEnabled(provider: String) {}
override fun onProviderDisabled(provider: String) {}
private fun getProvider(accuracy: String?): String {
return when (accuracy) {
"high" -> LocationManager.GPS_PROVIDER
"low" -> LocationManager.PASSIVE_PROVIDER
else -> LocationManager.NETWORK_PROVIDER
}
}
}
Now I came accross this code but i dont see this getting used
class GooglePositionProvider(context: Context, listener: PositionListener) : PositionProvider(context, listener) {
private val fusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
@Suppress("DEPRECATION", "MissingPermission")
override fun startUpdates() {
val locationRequest = LocationRequest()
locationRequest.priority = getPriority(preferences.getString(MainFragment.KEY_ACCURACY, "medium"))
locationRequest.interval = if (distance > 0 || angle > 0) MINIMUM_INTERVAL else interval
fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, Looper.getMainLooper())
}
override fun stopUpdates() {
fusedLocationClient.removeLocationUpdates(locationCallback)
}
@SuppressLint("MissingPermission")
override fun requestSingleLocation() {
fusedLocationClient.lastLocation.addOnSuccessListener { location ->
if (location != null) {
listener.onPositionUpdate(Position(deviceId, location, getBatteryStatus(context)))
}
}
}
private val locationCallback: LocationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult) {
for (location in locationResult.locations) {
processLocation(location)
}
}
}
private fun getPriority(accuracy: String?): Int {
return when (accuracy) {
"high" -> LocationRequest.PRIORITY_HIGH_ACCURACY
"low" -> LocationRequest.PRIORITY_LOW_POWER
else -> LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
}
}
}
can you please let me know where is the fused lcoation used
This is how i have place trracr client in my existing app for location tracking Image Link
I am trying to fix 2 issues I am facing
Please suggest me how to avoid high accuracy wrong location from provider
The code is used here:
By the way, all your images are private, so can't see anything.
Hi,
Sorry for that , I have made it public https://drive.google.com/file/d/1mBzTcZk7Q8JY638qVjmDNTQmOybHIIU1/view?usp=drive_link
As in this image you can see i have added the traccar code in my app , i didn't add the this part of traccar code https://drive.google.com/file/d/10c9XnXaODx1nCdpj6W1pFntNLaPmCg3Q/view?usp=sharing. I didn't get why will this google folder be used, can u tell me if i need to add this ?
My app is just for internal company purpose, i am not publishing in play store.
These are the 2 issues i am facing as i mentioned above:
1.the location not send some scenarios
2.In some case wrong location is send - i can see accuracy very high in such case
As in my case can i just replace AndroidPositionProvider this code with content of GooglePositionProvider?
If you want to use Google provider, you have to build the Google flavor of the app.
In my case there is sudden completely different location updated - As below u can see Financial Center Street, Dubai, Dubai, AE in middle, As of my company requirement they need i have to send very accurate location always, there are not ok if i skip the location with high accuracy(>110), How can i acheive precise location? Please suggest