Skip to Content
MapQuest SDK
Hooks

useNavigation

const navigation: NavigationController = useNavigation()

Plan routes and control guidance from inside Navigation or a shared Navigation.Provider. For UI that updates when a trip starts or ends, use useNavigationSession.

Return Values

navigation is the controller for the nearest provider:

  • plan(itinerary, signal?) previews an itinerary without replacing the active trip. Request up to six additional routes with alternatives.
  • startNavigation(itineraryOrRouteId, signal?) starts guidance from an itinerary or a selected route ID.
  • stopNavigation() ends guidance and cancels any pending start.

Both plan() and startNavigation() accept an AbortSignal as the second argument.

Example

import { type Itinerary, useNavigation } from '@mapquest/sdk'
import { Button } from 'react-native'

export function StartTripButton({ itinerary }: { itinerary: Itinerary }) {
  const navigation = useNavigation()
  return <Button title="Start trip" onPress={() => navigation.startNavigation(itinerary)} />
}

This button skips the preview. If the user has selected a route from a plan, call navigation.startNavigation(selectedRoute.id) instead. See the turn-by-turn guide for a shared-screen setup and cancellation behavior.

On this page