The speed can jump even to 70km/h, I've never had such jumps before. I think it's related to poor reception, but still, the other app works fine, Maybe they filter out wrong data or they use a different way to get location? This is the code I'm using in a foreground service:

override fun onCreate() {
    super.onCreate()
    mHandlerThread.start()
    mBroadcastManager = LocalBroadcastManager.getInstance(this)
    createNotificationChanel()
    requestLocationUpdates()
}
@SuppressLint("MissingPermission")
@Synchronized private fun requestLocationUpdates() {
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
    createLocationRequest()
    val locationCallback: LocationCallback?
    locationCallback = object : LocationCallback() {
        @Synchronized override fun onLocationResult(locationResult: LocationResult) {
                val location = locationResult.lastLocation
                val speedKmph = ((location?.speed?: 0f) * 3.6).roundToInt()
                mSpeed = speedKmph
        }
    }
    mFusedLocationClient.requestLocationUpdates(
        mLocationRequest,
        locationCallback,
        mHandlerThread.looper
    )
}
@Synchronized   private fun createLocationRequest() {
 LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 1000)
 .setWaitForAccurateLocation(false)
 .setMinUpdateIntervalMillis(500)
 .build().also { mLocationRequest = it }
}
1

There are 1 best solutions below

0
Kevin Krumwiede On

GPS data is naturally noisy and is normally filtered with a Kalman filter or something similar. Different GPS receivers apply different amounts of filtering, and apps can apply their own additional filtering.