fix(compass): fix iOS heading in landscape mode#421
Merged
KristjanESPERANTO merged 1 commit intodomoritz:gh-pagesfrom May 6, 2026
Merged
fix(compass): fix iOS heading in landscape mode#421KristjanESPERANTO merged 1 commit intodomoritz:gh-pagesfrom
KristjanESPERANTO merged 1 commit intodomoritz:gh-pagesfrom
Conversation
iOS webkitCompassHeading is relative to device orientation. In landscape this can point the compass in the wrong direction. Apply screen orientation angle as compensation when available. Also handle 0 as a valid iOS heading and keep behavior safe when screen orientation is unavailable. Add regression tests for rotation compensation and fallback. Closes domoritz#262
domoritz
approved these changes
May 4, 2026
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.
After working on #420 I had another look at #262 and think we can go with this fix.
On iOS,
webkitCompassHeadingis relative to the physical device top, not the screen. In landscape mode the compass arrow therefore points in the wrong direction. This addsscreen.orientation.angleas a compensation offset (iOS 16.4+). On older devices the fallback is 0, which is no worse than before.Two smaller things fixed along the way:
webkitCompassHeading === 0(due north) was silently dropped by a falsy check - changed to!= null.% 360.Regression tests are included.
I don't have an iOS device to test on. The formula matches the workaround posted by the original reporter in #262, so I'm fairly confident it's correct and good to go.
Closes #262