Realtime gps optimized for efficiency
This commit is contained in:
parent
ddbc6dc872
commit
aa44494cbe
@ -139,7 +139,7 @@ class DumonGeolocation : Plugin() {
|
||||
latestAccuracy = location.accuracy.toDouble()
|
||||
latestTimestamp = location.time
|
||||
latestSource = if (isMockedLocation) "MOCK" else "GNSS"
|
||||
emitPositionUpdate()
|
||||
emitPositionUpdate(forceEmit = true) // force emit in driving
|
||||
}
|
||||
drivingEmitHandler?.postDelayed(this, drivingEmitIntervalMs)
|
||||
}
|
||||
@ -302,10 +302,9 @@ class DumonGeolocation : Plugin() {
|
||||
call.resolve(result)
|
||||
}
|
||||
|
||||
private fun emitPositionUpdate() {
|
||||
|
||||
private fun emitPositionUpdate(forceEmit: Boolean = false) {
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastEmitTimestamp < emitIntervalMs) return
|
||||
if (!forceEmit && now - lastEmitTimestamp < emitIntervalMs) return
|
||||
|
||||
val distance = calculateDistance(latestLatitude, latestLongitude, prevLatitude, prevLongitude)
|
||||
val speedNow = latestImu?.speed ?: 0f
|
||||
@ -324,7 +323,7 @@ class DumonGeolocation : Plugin() {
|
||||
|
||||
val shouldEmit = isSignificantChange || speedChanged || directionChanged
|
||||
|
||||
if (shouldEmit) {
|
||||
if (forceEmit || shouldEmit) {
|
||||
prevLatitude = latestLatitude
|
||||
prevLongitude = latestLongitude
|
||||
prevSpeed = speedNow
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user