Integration

The tile service integrates easily with Mapbox and other maps providers (Google Maps, Leaflet etc). However to access the tile service, you need to include authorization headers in your requests. The method for setting these headers varies per platform. Below, we provide examples for configuring authorization headers with different Mapbox SDKs:

For an overview on API authorization please head to this section.

Web

With the MapboxGL JS library, you can use the transformRequest function to add the necessary headers. Get started with this example:

A fully working example with Mapbox Maps using the MVT API can be found here, while an example with Google Maps using the JSON API is available here.

iOS

When using Mapbox version 9 or lower for iOS you will need to use a method swizzler. A more detailed explanation is provided inside this Github issue.

When using Mapbox version 10 or up for iOS, you can subclass the networking layer and add your headers. At the time of writing, it should look like this:

Don't forget to set this subclass early on in the app's lifecycle:

Android

Install and configure the Mapbox SDK for Android as explained on Mapbox documentation.

Set the Mapbox access token and custom headers in the application object or in the activity that contains the MapView:

React Native

For React Native we suggest using @rnmapbox/maps to render the map component in your app, but you can choose to use other implementations. You can set the necessary headers in your entry file or in the component that will contain the map, based on the lifecycle of your map, as follows: