MentraOS / mobile /docs /module /crust /Navigation.md
Anirudh1950's picture
Add files using upload-large-folder tool
b2a9056 verified
|
Raw History Blame Contribute Delete
2.55 kB

Crust: Navigation

How the crust native module delivers turn-by-turn navigation to JS.

Overview

Turn-by-turn guidance backed by Google Navigation SDK. Runs on iOS and Android with parity. JS calls the module via Expo AsyncFunctions; the native side streams results back as events.

Flow

  1. JS calls requestNavigationPermission() β€” shows the Google T&C dialog. Must be accepted before startNavigation works.
  2. JS calls startNavigation(lat, lng, options) with optional stops, mode, simulate, speedMultiplier.
  3. Native NavigationManager registers the Google API key, creates an off-screen GMSMapView, grabs its navigator, sets waypoints, and activates guidance. Voice is muted.
  4. As the route is computed and the user moves, the manager emits events to JS:
    • onNavRoute β€” polyline points + step metadata (road / maneuver / distance).
    • onNavManeuver β€” current step, distance to next turn, ETA.
    • onNavLocation β€” road-snapped GPS ticks.
    • onNavRerouting β€” fired when the route changes.
    • onNavOffRoute β€” once per off-route episode (>30m from polyline).
    • onNavArrived β€” final waypoint reached.
  5. JS calls stopNavigation() β€” tears down the navigator, clears callbacks, resets cached state.

Simulation mode replays a route at speedMultiplierΓ— speed; a 1Hz polling timer reads mapView.myLocation as a fallback when the road-snapped provider stays quiet.

Files

iOS

  • CrustModule.swift β€” Expo module entry point; declares AsyncFunctions and event names, bridges to the manager below.
  • NavigationManager.swift β€” owns the GMSNavigator lifecycle, route/step/off-route detection, simulation polling.
  • NavPayloads.swift β€” maneuverString() enum mapping and pathToPoints() polyline encoder.

Android