Skip to content

Location: Fix speed calculation for sub-second updates - #3737

Open
DaVinci9196 wants to merge 1 commit into
microg:masterfrom
DaVinci9196:location-subsecond-speed
Open

Location: Fix speed calculation for sub-second updates#3737
DaVinci9196 wants to merge 1 commit into
microg:masterfrom
DaVinci9196:location-subsecond-speed

Conversation

@DaVinci9196

Copy link
Copy Markdown
Contributor

Calculate derived speed using millisecond precision and only set it
for valid time deltas and finite results.

This prevents Infinity or NaN speed values from reaching location clients.

@mar-v-in mar-v-in added this to the 0.3.17 milestone Aug 25, 2026
Comment on lines +73 to +83
if (!location.hasSpeed()) {
val speed = previousLocation.distanceTo(location) * 1000f / elapsedMillis
if (speed.isFinite()) {
location.speed = speed
LocationCompat.setSpeedAccuracyMetersPerSecond(location, speed)
}
}
if (!location.hasBearing() && location.speed > 0.5f) {
location.bearing = previousLocation.bearingTo(location)
LocationCompat.setBearingAccuracyDegrees(location, 180.0f)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mar-v-in
I'm not sure but: what happens if the speed wasn't finite so it remain unset and then it check location.speed > 0.5f?
Maybe it need another location.hasSpeed() check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants