why have you used Location Manager to get the location instead of Fused Location Provider?

Shifa7 months ago

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

Asem Khurshid SM-A235F samsung	2023-09-13 15:12:52	25.097836°	55.156403°	0.00 kn	Al Burooj Street, Dubai Knowledge Park, Dubai, AE	78.90 m
Asem Khurshid SM-A235F samsung	2023-09-13 15:17:52	25.097836°	55.156403°	0.00 kn	Al Burooj Street, Dubai Knowledge Park, Dubai, AE	78.90 m
Asem Khurshid SM-A235F samsung	2023-09-13 15:22:57	25.201504°	55.276838°	0.00 kn	Financial Center Street, Dubai, Dubai, AE	78.90 m ----------------------------this
Asem Khurshid SM-A235F samsung	2023-09-13 15:27:53	25.201504°	55.276838°	0.00 kn	Financial Center Street, Dubai, Dubai, AE	78.90 m-----------------------------this
Asem Khurshid SM-A235F samsung	2023-09-13 15:33:53	25.097838°	55.156403°	0.00 kn	Al Burooj Street, Dubai Knowledge Park, Dubai, AE	78.90 m
Asem Khurshid SM-A235F samsung	2023-09-13 15:40:53	25.097267°	55.156382°	0.00 kn	Al Burooj Street, Dubai Knowledge Park, Dubai, AE	78.90 m
Asem Khurshid SM-A235F samsung	2023-09-13 15:45:53	25.097267°	55.156382°	0.00 kn	Al Burooj Street, Dubai Knowledge Park, Dubai, AE	78.90 m
Anton Tananaev7 months ago

Who told you that we don't use fused location provider? We use both.

Shifa7 months ago

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

Shifa7 months ago

This is how i have place trracr client in my existing app for location tracking Image Link

Shifa7 months ago

I am trying to fix 2 issues I am facing

  1. the location not send some scenarios
    traccar server Image
  2. in some case wrong location is send - i can see accuracy very high in such case image link

Please suggest me how to avoid high accuracy wrong location from provider

Shifa7 months ago
Anton Tananaev7 months ago

The code is used here:

https://github.com/traccar/traccar-client-android/blob/master/app/src/google/java/org/traccar/client/PositionProviderFactory.kt#L23

By the way, all your images are private, so can't see anything.

Shifa7 months ago

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 ?

Shifa7 months ago

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

Shifa7 months ago

As in my case can i just replace AndroidPositionProvider this code with content of GooglePositionProvider?

Anton Tananaev7 months ago

If you want to use Google provider, you have to build the Google flavor of the app.