Turn-by-turn navigation
Render <Navigation /> on the screen where the user follows a route. It provides the guidance map and follow camera. Leaving that screen doesn't end the trip.
Share a trip across screens
If one screen plans a trip and another displays guidance, place Navigation.Provider above both. Mounting the provider does not calculate a route or start location updates.
import { Navigation } from '@mapquest/sdk'
import { Stack } from 'expo-router'
export default function TripLayout() {
return (
<Navigation.Provider>
<Stack />
</Navigation.Provider>
)
}Start or end a trip
Inside the provider, use useNavigation() for commands and useNavigationSession() to decide which button to show:
import { type Itinerary, useNavigation, useNavigationSession } from '@mapquest/sdk'
import { Button } from 'react-native'
function TripButton({ itinerary }: { itinerary: Itinerary }) {
const navigation = useNavigation()
const session = useNavigationSession()
return session
? <Button title="End trip" onPress={navigation.stopNavigation} />
: <Button title="Start trip" onPress={() => navigation.startNavigation(itinerary)} />
}Compare and select routes
Call navigation.plan({ ...itinerary, alternatives: 2 }, signal) to preview alternatives. When the user selects a route, pass its id to navigation.startNavigation(). If they dismiss the preview, the active trip continues unchanged.
See Itinerary for waypoint rules and routing preferences, or useNavigation() for the controller's commands.
A pending startNavigation() rejects with AbortError if you abort its signal, start another trip, or call stopNavigation(). After a session ends, its listeners no longer receive position updates.
Customize the guidance screen
Pass children to Navigation to arrange the map and camera alongside your own controls. For example, place an end-trip button below a dark map. Changing this layout doesn't change the active session.
import { MapTheme, Navigation, useNavigation, useNavigationSession } from '@mapquest/sdk'
import { Button } from 'react-native'
function TripControls() {
const session = useNavigationSession()
const navigation = useNavigation()
if (!session) return null
return <Button title="End trip" onPress={navigation.stopNavigation} />
}
export default function GuidanceScreen() {
return (
<Navigation>
<Navigation.Map theme={MapTheme.DARK} style={{ flex: 1 }}>
<Navigation.Camera />
</Navigation.Map>
<TripControls />
</Navigation>
)
}Background guidance
To keep a trip running when the app moves to the background, set enableBackgroundGuidance: true in the Expo plugin options and rebuild your app. This configures background location on iOS and the location foreground service on Android.
Request foreground location permission and start guidance while the app is in use. On iOS, When In Use authorization lets that active trip continue receiving updates in the background. You don't need a second prompt for Always authorization.