Skip to content

feat: native compass bearing integration to current location indicator on maps - #2406

Open
PeterBaker0 wants to merge 18 commits into
mainfrom
feat/native-compass-integration
Open

PeterBaker0 wants to merge 18 commits into
mainfrom
feat/native-compass-integration

Conversation

@PeterBaker0

@PeterBaker0 PeterBaker0 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

feat: improve device compass and GPS bearing fallback

Description

Provide a stable device-bearing indicator using the compass when available and GPS course-over-ground as a fallback.

Proposed Changes

  • Check compass availability before starting Capgo Compass:
    • On Android, verify that both the accelerometer and magnetic-field sensor are available.
    • On iOS, use CLLocationManager.headingAvailable() to check whether compass heading is supported.
    • Skip the compass session when unavailable, allowing GPS heading fallback.
  • Improve compass heading stability and reliability:
    • Apply time-aware smoothing to reduce jitter while responding faster to turns.
    • Hold sudden large heading changes until confirmed to avoid unexpected jumps.
    • Ignore the first Android compass reading to avoid potentially invalid startup values.
    • Fall back to GPS course-over-ground when Android compass readings become stale.
    • Maintain magnetic declination correction to convert magnetic headings to true north.
    • Compare smoothed headings against the last published heading so that small changes can accumulate.
  • Accept GPS course at speeds of at least 0.5 m/s and clear the GPS heading when the speed or course becomes unreliable.
  • Prioritise compass heading over GPS course when available, hide the heading triangle when neither source provides a usable bearing, and restore it when a valid heading becomes available.
  • Reuse existing marker styles and avoid redundant triangle style updates.
  • Add Vitest coverage for sensor availability, compass behaviour, GPS fallback, heading visibility, movement resumption, and native compass lifecycle handling.

How to Test

  • Run pnpm --filter=@faims3/forms exec vitest --run lib/components/maps/heading.test.ts lib/hooks/useDeviceHeading.test.tsx lib/components/maps/MapComponent.test.tsx.
  • Run pnpm --filter=@faims3/forms typecheck.
  • On Android, verify compass behaviour on a device with the required sensors and GPS fallback on a device without a magnetometer.
  • Verify that the GPS heading triangle disappears when stationary or moving below the speed threshold and reappears when movement resumes, if no compass heading is available.
  • Verify that the compass heading remains visible while stationary when a valid compass reading is available.
  • Open and close maps repeatedly to verify that compass updates continue working correctly.
  • Rotate and zoom the map to verify that the heading triangle maintains the correct direction and offset from the GPS marker.
  • On iOS, verify compass heading and the map indicator.

Additional Information

GPS fallback has been tested on an Android device without a magnetometer. iOS physical-device verification remains outstanding.

The Android sensor check uses a small native bridge; Capgo Compass and device permissions remain unchanged.

Checklist

  • I have confirmed all commits have been signed.
  • I have added JSDoc style comments to any new functions or classes.
  • I have added tests for new code if appropriate
  • Relevant documentation such as READMEs, guides, and class comments are updated.

Signed-off-by: Peter Baker <peter.baker122@csiro.au>
Signed-off-by: Peter Baker <peter.baker122@csiro.au>
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

E2E ✅ passed

Result ✅ Suite passed
Artifacts Download e2e-artifacts-45545165393.zip
Run View workflow run

After downloading and extracting the .zip file, open artifacts/index.html (failures listed first).

Updated for commit 0c8da79

@PeterBaker0
PeterBaker0 marked this pull request as draft October 5, 2026 03:38
@PeterBaker0

Copy link
Copy Markdown
Contributor Author

On device (Android) it feels jittery and a bit inconsistent. need to have a look at smoothing more closely.

@PeterBaker0

Copy link
Copy Markdown
Contributor Author

@xinyuhoulucy this is a starting point

@xinyuhoulucy
xinyuhoulucy marked this pull request as ready for review November 16, 2026 06:29
xinyuhoulucy and others added 10 commits November 24, 2026 12:58
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
@xinyuhoulucy
xinyuhoulucy force-pushed the feat/native-compass-integration branch from 05e8c71 to 7129197 Compare November 25, 2026 04:04
xinyuhoulucy and others added 3 commits November 25, 2026 15:05
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>
Signed-off-by: Xinyu Hou <xinyu.hou@csiro.au>

This branch has not been deployed

No deployments
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.

2 participants