Mapbox Navigation in React Native: A Complete Guide - React Native Expert
banner shap banner shap

Advanced In-App Navigation with Mapbox in React Native

Learn how to implement advanced in-app navigation with Mapbox in React Native. Includes voice guidance, offline maps, and real-time directions.

Apr 24, 2025

Save for later

mapbox in react native

Introduction:

In-app navigation has evolved from simple direction lines on maps to full-fledged systems with voice-guided turn-by-turn navigation, real-time traffic awareness, offline capabilities, and custom UI controls. For React Native developers, Mapbox emerges as a robust and highly customizable alternative to Google Maps, especially for applications that need more design freedom or offline functionality.

In this blog, we’ll walk through how to integrate Mapbox into a React Native app to implement real-time, turn-by-turn in-app navigation. From initial setup to route rendering, user location tracking, voice-guided directions, and offline map caching, we cover everything.

Why Choose Mapbox for React Native Navigation?

Mapbox provides numerous advantages for building navigation apps in React Native:

Key Advantages:

  • Highly Customizable: Fully control map styles, features, and layers.
  • Turn-by-Turn Navigation: Native SDKs with accurate, real-time directions.
  • Offline Support: Cache maps and routes for disconnected environments.
  • Performance Optimized: Vector maps are lighter and render faster.
  • Open Pricing Model: Includes generous free-tier and usage-based pricing.

Use Cases for In-App Navigation

  • Delivery Apps – Real-time directions for drivers.
  • Fleet Management – Dispatch, ETA, and rerouting.
  • Tourist Guides – Navigation to attractions with multimedia.
  • Ride-Sharing – Step-by-step route navigation for drivers.
  • Onsite Inspections – Map-based routing for technicians

Project Setup: Installing Mapbox in React Native

Dependencies:

				
					npm install @rnmapbox/maps
npx pod-install

				
			

In a traditional implementation, React Native would send updates over the bridge to update the UI. With Fabric, these updates are directly handled, minimizing performance bottlenecks.

Configure Access Token:

Register on https://account.mapbox.com and obtain an access token.

In App.tsx:

				
					import MapboxGL from '@rnmapbox/maps';
MapboxGL.setAccessToken('YOUR_ACCESS_TOKEN');

				
			

iOS Setup

In ios/YourApp/Info.plist:

				
					<key>MGLMapboxAccessToken</key>
<string>YOUR_ACCESS_TOKEN</string>
				
			

Android Setup

In android/app/src/main/AndroidManifest.xml:

				
					<meta-data
  android:name="com.mapbox.AccessToken"
  android:value="YOUR_ACCESS_TOKEN"/>

				
			

Displaying a Customizable Map

				
					<MapboxGL.MapView
  style={{ flex: 1 }}
  styleURL={MapboxGL.StyleURL.NavigationNight}
  compassEnabled
  logoEnabled={false}>

  <MapboxGL.Camera
    zoomLevel={15}
    followUserLocation
    followUserMode="normal"
  />

  <MapboxGL.UserLocation visible />

</MapboxGL.MapView>

				
			

Pro Tip: Use Mapbox Studio to build a completely unique map style that matches your app branding.

Getting User Location and Permissions

Ask Runtime Location Permission

Install:

				
					npm install react-native-permissions

Ask for location permission before using the map:
import { request, PERMISSIONS } from 'react-native-permissions';

await request(
  Platform.OS === 'ios'
    ? PERMISSIONS.IOS.LOCATION_WHEN_IN_USE
    : PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
);

				
			

Implementing Turn-by-Turn Navigation

Option 1: react-native-mapbox-navigation

This is a wrapper for the native Mapbox SDK (Android & iOS).

				
					npm install react-native-mapbox-navigation
				
			

Example Usage:

				
					<MapboxNavigation
  origin={[lng1, lat1]}
  destination={[lng2, lat2]}
  shouldSimulateRoute={false}
  onLocationChange={loc => console.log(loc)}
  onCancelNavigation={() => console.log('Navigation canceled')}
  onArrive={() => alert('You’ve arrived!')}
/>

				
			

Option 2: Native Bridge to Mapbox Navigation SDKs

Use:

  • Android: mapbox.navigation:android
  • iOS: MapboxNavigation-Swift

Wrap SDK in native code and expose via NativeModules.

Advanced Use Cases

Multiple Stops (Waypoints):

Add waypoints between origin and destination:
json

				
					[
  { "latitude": 37.7749, "longitude": -122.4194 },
  { "latitude": 37.8044, "longitude": -122.2711 },
  { "latitude": 37.6879, "longitude": -122.4702 }
]

				
			

Use waypoints prop if available or update your SDK for routing.

Calculating and Displaying ETA

Using Mapbox Directions API

When requesting directions, the API returns a duration (in seconds) which can be converted into a readable ETA.

API Example:

				
					https://api.mapbox.com/directions/v5/mapbox/driving/{origin};{destination}?access_token=YOUR_ACCESS_TOKEN

				
			

Sample Response Snippet:

				
					"routes": [
  {
    "duration": 1536, // in seconds
    "distance": 10532, // in meters
  }
]

				
			

Display ETA in UI

				
					const getETAString = (seconds: number) => {
  const minutes = Math.round(seconds / 60);
  return `${minutes} min`;
};

<Text>Estimated Arrival: {getETAString(route.duration)}</Text>

				
			

You can update this value on every onRouteProgressChange callback to reflect real-time traffic and movement.

Automatic Rerouting

Sometimes users go off-route — they take a wrong turn or a detour. Mapbox Navigation SDK can detect these deviations and offer a new route.

Auto Rerouting Support:

In react-native-mapbox-navigation, rerouting is handled automatically by default.

Rerouting Trigger:

  • When deviation from route is detected,
  • SDK recalculates the best route using current position.

Manual Rerouting:

You can use the onLocationChange event to detect major deviation and manually request a new route from Mapbox Directions API.

				
					if (distanceFromRoute(userLocation, routeGeometry) > threshold) {
  fetchNewRoute(userLocation, destination);
}

				
			

Use @turf/distance to calculate deviation from the original path.

Offline Maps and Navigation

Download Region:

				
					MapboxGL.offlineManager.createPack({
  name: 'nyc-region',
  styleURL: MapboxGL.StyleURL.Street,
  bounds: [[-74.1, 40.7], [-73.9, 40.8]],
  minZoom: 10,
  maxZoom: 18
}, progress => {
  console.log('Download progress:', progress);
});
				
			

This makes your navigation usable even without internet!

Advanced: Navigation Event Handling

  • onError – Any error during navigation
  • onLocationChange – Every user GPS update
  • onArrive – Triggers on arrival at the final destination
  • onRouteProgressChange – For step updates

Use these to:

  • Update UI (next turn, distance)
  • Send progress to backend
  • Animate marker on route

Conclusion

Mapbox offers React Native developers a robust way to integrate real-time, customizable, and offline-capable in-app navigation. Whether you’re building a logistics app, tour app, or anything involving movement and direction, this integration gives you the performance and user experience of native navigation apps.

With this blog, you’re now equipped to:

  • Set up Mapbox in React Native,
  • Display maps and user location,
  • Enable voice-based navigation,
  • Handle navigation events,
  • Cache maps for offline usage.

Comparing Gluestack UI with Other React Native UI Libraries

Feature Gluestack UI NativeBase React Native Paper Material UI
Performance Optimized
Customization
Prebuilt Components
Theming Support
Atomic Styling
Re-Renders Optimized
Mobile App Development Company USA

Searching for the Best Mobile App Development Services for Your Business?

Hire our React Native Developers to analyze your business requirements and develop a tailored mobile app that drives results. Discover top-tier mobile app development services designed to elevate your business.

Schedule Meeting Schedule a Consultation
5/5 - (1 vote)