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