Skip to main content

Navigation

const Navigation: object;

The headless navigation API: route requests, the app's single guidance session, and its events. It's also the default export.

Type Declaration​

addArriveListener()​

addArriveListener(listener: (event: ArriveEvent) => void): EventSubscription;

Called when guidance reaches a waypoint, the final destination included.

Parameters​

ParameterType
listener(event: ArriveEvent) => void

Returns​

EventSubscription

addCameraStateListener()​

addCameraStateListener(listener: (state: CameraState) => void): EventSubscription;

Called whenever the camera state changes, whether from JS, guidance or a map gesture.

Parameters​

ParameterType
listener(state: CameraState) => void

Returns​

EventSubscription

addLocationListener()​

addLocationListener(listener: (event: LocationEvent) => void): EventSubscription;

The location snapped to the road or route, with its speed limit and road name.

Parameters​

ParameterType
listener(event: LocationEvent) => void

Returns​

EventSubscription

addOffRouteListener()​

addOffRouteListener(listener: (offRoute: boolean) => void): EventSubscription;

Called with true when the user leaves the route, then with false once guidance follows a route again.

Parameters​

ParameterType
listener(offRoute: boolean) => void

Returns​

EventSubscription

addRouteChangeListener()​

addRouteChangeListener(listener: (event: RouteChangeEvent) => void): EventSubscription;

Called when guidance switches to another route on its own. Every listener gets the same new Route; the previous one stays valid until released.

Parameters​

ParameterType
listener(event: RouteChangeEvent) => void

Returns​

EventSubscription

addRouteProgressListener()​

addRouteProgressListener(listener: (event: RouteProgressEvent) => void): EventSubscription;

Called as guidance moves along the route, from the headless API and <NavigationView> alike. Events already on their way to JS can still arrive after stopNavigation.

Parameters​

ParameterType
listener(event: RouteProgressEvent) => void

Returns​

EventSubscription

addVoiceInstructionListener()​

addVoiceInstructionListener(listener: (event: VoiceInstructionEvent) => void): EventSubscription;

Called when an instruction is due, whether or not the SDK speaks it; for apps doing their own text to speech.

Parameters​

ParameterType
listener(event: VoiceInstructionEvent) => void

Returns​

EventSubscription

getCameraState()​

getCameraState(): CameraState;

The camera state of navigation maps, see setCameraState.

Returns​

CameraState

getRouteStats()​

getRouteStats(): RouteStats;

Counts of native routes, for leak checks.

Returns​

RouteStats

getSdkVersion()​

getSdkVersion(): string;

Version of the native Mapbox Navigation SDK linked into the app.

Returns​

string

isVoiceMuted()​

isVoiceMuted(): boolean;

Whether voice instructions are muted, by setVoiceMuted or <NavigationView>'s mute button.

Returns​

boolean

previewRoute()​

previewRoute(route: Route | null): void;

Shows route on navigation maps until guidance starts or stopNavigation is called; null removes it. Throws if route was released.

Parameters​

ParameterType
routeRoute | null

Returns​

void

requestRoutes()​

requestRoutes(options: RouteRequestOptions): Promise<RouteResponse>;

Requests routes through options.waypoints. The routes hold native memory: release() the ones you don't keep. Rejects with fewer than two waypoints.

Parameters​

ParameterType
optionsRouteRequestOptions

Returns​

Promise<RouteResponse>

setAccessToken()​

setAccessToken(accessToken: string): void;

Must be called before any request; navigation is billed to this token.

Parameters​

ParameterType
accessTokenstring

Returns​

void

setCameraState()​

setCameraState(state: CameraState): void;

Camera of every navigation map (<MapView mapViewImpl={NAVIGATION_MAP_VIEW_IMPL}>). idle hands the camera back to the user's gestures and @rnmapbox/maps Camera. Guidance switches it to following; a pan, zoom, rotate or pitch gesture on any navigation map switches it to idle. Use addCameraStateListener to follow those changes.

Parameters​

ParameterType
stateCameraState

Returns​

void

setVoiceMuted()​

setVoiceMuted(muted: boolean): void;

Mutes the SDK's voice instructions for all guidance, including <NavigationView>.

Parameters​

ParameterType
mutedboolean

Returns​

void

startActiveGuidance()​

startActiveGuidance(route: Route, options?: StartActiveGuidanceOptions): Promise<void>;

Starts active guidance along route, replacing any active guidance, and switches the camera to following. Rejects if route was released. Guidance keeps its own reference to the native route until stopNavigation, so route can be released at any time.

Parameters​

ParameterType
routeRoute
options?StartActiveGuidanceOptions

Returns​

Promise<void>

stopNavigation()​

stopNavigation(): void;

Stops guidance and removes the route from navigation maps. The camera switches to idle and eases back to north-up.

Returns​

void