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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
listener | (event: VoiceInstructionEvent) => void |
Returns
EventSubscription
getCameraState()
getCameraState(): CameraState;
The camera state of navigation maps, see setCameraState.
Returns
getRouteStats()
getRouteStats(): RouteStats;
Counts of native routes, for leak checks.
Returns
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
| Parameter | Type |
|---|---|
route | Route | 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
| Parameter | Type |
|---|---|
options | RouteRequestOptions |
Returns
Promise<RouteResponse>
setAccessToken()
setAccessToken(accessToken: string): void;
Must be called before any request; navigation is billed to this token.
Parameters
| Parameter | Type |
|---|---|
accessToken | string |
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
| Parameter | Type |
|---|---|
state | CameraState |
Returns
void
setVoiceMuted()
setVoiceMuted(muted: boolean): void;
Mutes the SDK's voice instructions for all guidance, including <NavigationView>.
Parameters
| Parameter | Type |
|---|---|
muted | boolean |
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
| Parameter | Type |
|---|---|
route | Route |
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