Location: Fix speed calculation for sub-second updates - #3737
Open
DaVinci9196 wants to merge 1 commit into
Open
Conversation
mar-v-in
approved these changes
Aug 25, 2026
ale5000-git
reviewed
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) | ||
| } |
Member
There was a problem hiding this comment.
@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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.