fix: add eventSink fallback for speed calc, fix UI title
This commit is contained in:
parent
b5fabd980f
commit
8884bdcb40
1 changed files with 35 additions and 8 deletions
|
|
@ -323,24 +323,47 @@ class LocationTrackingService : Service() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalSpeed == null || finalSpeed <= 0) {
|
if (finalSpeed == null || finalSpeed <= 0) {
|
||||||
logEvent("SPEED_CALC", "Speed calculation failed - insufficient data")
|
logEvent("SPEED_CALC", "Speed calculation failed - sending without speed")
|
||||||
return
|
// Fallback: send location without speed rather than losing it
|
||||||
|
} else {
|
||||||
|
logEvent("LOCATION", "Lat: ${location.latitude}, Lon: ${location.longitude}, Calc Speed: ${finalSpeed}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val speedToSend = if (finalSpeed != null && finalSpeed > 0) finalSpeed else null
|
||||||
|
|
||||||
val traccarLocation = TraccarLocation(
|
val traccarLocation = TraccarLocation(
|
||||||
timestamp = location.time,
|
timestamp = location.time,
|
||||||
latitude = location.latitude,
|
latitude = location.latitude,
|
||||||
longitude = location.longitude,
|
longitude = location.longitude,
|
||||||
accuracy = if (location.hasAccuracy()) location.accuracy else null,
|
accuracy = if (location.hasAccuracy()) location.accuracy else null,
|
||||||
speed = finalSpeed,
|
speed = speedToSend,
|
||||||
heading = if (location.hasBearing()) location.bearing else null,
|
heading = if (location.hasBearing()) location.bearing else null,
|
||||||
altitude = if (location.hasAltitude()) location.altitude else null,
|
altitude = if (location.hasAltitude()) location.altitude else null,
|
||||||
isMoving = finalSpeed > 1.0f
|
isMoving = (speedToSend ?: 0f) > 1.0f
|
||||||
)
|
)
|
||||||
|
|
||||||
logEvent("LOCATION", "Lat: ${location.latitude}, Lon: ${location.longitude}, Calc Speed: ${finalSpeed}")
|
updateNotificationSpeed(location, speedToSend)
|
||||||
|
|
||||||
updateNotificationSpeed(location, finalSpeed)
|
BridgeModule.eventSink?.success(mapOf(
|
||||||
|
"latitude" to location.latitude,
|
||||||
|
"longitude" to location.longitude,
|
||||||
|
"accuracy" to if (location.hasAccuracy()) location.accuracy else null,
|
||||||
|
"speed" to speedToSend,
|
||||||
|
"heading" to if (location.hasBearing()) location.bearing else null,
|
||||||
|
"altitude" to if (location.hasAltitude()) location.altitude else null,
|
||||||
|
"timestamp" to location.time
|
||||||
|
))
|
||||||
|
|
||||||
|
prefs.edit().apply {
|
||||||
|
putFloat("last_latitude", location.latitude.toFloat())
|
||||||
|
putFloat("last_longitude", location.longitude.toFloat())
|
||||||
|
if (location.hasAccuracy()) putFloat("last_accuracy", location.accuracy)
|
||||||
|
if (speedToSend != null) putFloat("last_speed", speedToSend)
|
||||||
|
if (location.hasBearing() && location.bearing >= 0) putFloat("last_heading", location.bearing)
|
||||||
|
if (location.hasAltitude() && location.altitude != 0.0) putFloat("last_altitude", location.altitude.toFloat())
|
||||||
|
putLong("last_timestamp", location.time)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
|
||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
sendLocationToServer(traccarLocation)
|
sendLocationToServer(traccarLocation)
|
||||||
|
|
@ -480,10 +503,14 @@ class LocationTrackingService : Service() {
|
||||||
notificationManager.notify(NOTIFICATION_ID, notification)
|
notificationManager.notify(NOTIFICATION_ID, notification)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateNotificationSpeed(location: Location, speed: Float) {
|
private fun updateNotificationSpeed(location: Location, speed: Float?) {
|
||||||
val content = buildString {
|
val content = buildString {
|
||||||
append("Lat: %.4f Lon: %.4f".format(location.latitude, location.longitude))
|
append("Lat: %.4f Lon: %.4f".format(location.latitude, location.longitude))
|
||||||
append("\nSpeed: %.0f km/h (calc)".format(speed * 3.6))
|
if (speed != null && speed > 0) {
|
||||||
|
append("\nSpeed: %.0f km/h (calc)".format(speed * 3.6))
|
||||||
|
} else {
|
||||||
|
append("\nSpeed: -- km/h")
|
||||||
|
}
|
||||||
val time = java.text.SimpleDateFormat("HH:mm:ss", java.util.Locale.getDefault())
|
val time = java.text.SimpleDateFormat("HH:mm:ss", java.util.Locale.getDefault())
|
||||||
.format(java.util.Date(location.time))
|
.format(java.util.Date(location.time))
|
||||||
append("\nLast: $time")
|
append("\nLast: $time")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue