Overview
Mapbox requires an access token to authenticate API requests. This guide walks you through obtaining a Mapbox access token and setting it up in your React Native application.Prerequisites
- A Mapbox account (free to create)
- Installed
@rnmapbox/mapspackage
Obtaining Your Access Token
Create a Mapbox account
If you don’t have a Mapbox account yet, sign up for free.
Access your tokens page
Navigate to your Mapbox account page to view and manage your access tokens.
Setting the Access Token in Your App
Once you have your access token, you need to set it in your React Native application. Add this code early in your app’s lifecycle, typically in your mainApp.js or App.tsx file:
Complete Example
Here’s a complete example showing where to place the access token configuration:Best Practices
Using Environment Variables
For better security, store your access token in an environment variable:Additional Configuration
Disabling Telemetry
By default, Mapbox collects telemetry data. If you want to disable this:For more information about Mapbox telemetry, visit mapbox.com/telemetry.
Android: Setting Connection Status
If you’re hosting styles and sources on localhost during development, you may need to manually set the connection status:true for connected, false for disconnected, or null to let ConnectivityManager determine the state.
Next Steps
Now that you’ve set up your access token, you’re ready to:- Complete platform-specific setup for iOS or Android
- Learn about Expo setup if using Expo
- Explore the example code and start building your map application