Skip to content

fix(compass): fix iOS heading in landscape mode#421

Merged
KristjanESPERANTO merged 1 commit intodomoritz:gh-pagesfrom
KristjanESPERANTO:compass
May 6, 2026
Merged

fix(compass): fix iOS heading in landscape mode#421
KristjanESPERANTO merged 1 commit intodomoritz:gh-pagesfrom
KristjanESPERANTO:compass

Conversation

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator

After working on #420 I had another look at #262 and think we can go with this fix.

On iOS, webkitCompassHeading is relative to the physical device top, not the screen. In landscape mode the compass arrow therefore points in the wrong direction. This adds screen.orientation.angle as 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.
  • The result is now normalized with % 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

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
@KristjanESPERANTO KristjanESPERANTO merged commit 28eea30 into domoritz:gh-pages May 6, 2026
1 check passed
@KristjanESPERANTO KristjanESPERANTO deleted the compass branch May 6, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direction not updated on screen rotation

2 participants