Speed accuracy enhancements.

Improved Speed and Trip accuracy.
This commit is contained in:
justin authored and GitHub committed 2025-05-05 18:25:05 -07:00
1 parent bbe10d7d28
commit 85d2a39fe2
1 file changed
+13 -5
+13 -5
View File
@@ -117,20 +117,28 @@ class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
return
}
// Skip updates if accuracy is too poor (≥ 20 meters)
guard latest.horizontalAccuracy >= 0 && latest.horizontalAccuracy < 20 else {
print("Skipping update due to poor accuracy: \(latest.horizontalAccuracy)")
return
}
// Logging raw location data for debugging
print("New location: \(latest.coordinate.latitude), \(latest.coordinate.longitude)")
print("Speed (m/s): \(latest.speed)")
print("Speed (MPH): \(latest.speed * 2.23694)")
print("Accuracy: \(latest.horizontalAccuracy)")
DispatchQueue.main.async {
// Ensure speed is non-negative (as negative = invalid)
// Ensure speed is non-negative
let rawSpeed = max(latest.speed, 0)
// Convert from meters per second to MPH
let mph = rawSpeed * 2.23694
// Ignore very small fluctuations when stopped (less than 0.5 m/s)
let filteredSpeed = rawSpeed < 0.5 ? 0 : rawSpeed
// Update published properties to refresh UI
// Convert from m/s to MPH
let mph = filteredSpeed * 2.23694
// Update UI-bound values
self.speed = Int(mph.rounded())
self.location = latest
self.accuracy = latest.horizontalAccuracy