Import MapBox Matrix Data to Google Sheets
- Before You Begin
- Part 1: Get your Mapbox API Token
- Part 2: Create your API Request URL
- Part 3: Pull MapBox API data into Sheets
- Part 4: More Example API URLs
- Part 5: Limitations
BEFORE YOU BEGIN
Click here to install the API Connector add-on from the Google Marketplace.
PART 1: GET YOUR MAPBOX API TOKEN
Matrix MapBox API is part of the Navigation service that MapBox provides. It returns a duration or distance of the fastest route between passed geographical points. Duration is given in seconds, while the distance is given in meters.
- To start using the MapBox API, we will need to register on the MapBox site. After email confirmation, you will be directed to this page which contains a default public token. However, we would need to make a personal one. Click on the button Create a token.
Name your token and select all the scopes, and then save it.
Now you get your token, that you will need to run your requests!
PART 2: CREATE YOUR API REQUEST URL
To create API requests, we will use some examples provided in the MapBox Matrix API documentation.
- API root: https://api.mapbox.com/directions-matrix/v1/
To retrieve directions you should use the following API link:
PART 3: PULL MAPBOX API DATA INTO GOOGLE SHEETS
In this example, we will request a duration of the fastest driving routes between three geographical points: (-122.42, 37.78), (-122.45, 37.91), and (-122.48, 37.73).
- Open up Google Sheets and click Add-ons > API Connector > Open.
- In the Create tab, enter the API URL constructed like this:
3. Now create a new tab, give it a name and click Set current to use that tab as your data destination.
4. Give a name to your request and click run!
5. Now you should be able to see the pulled data! This API request returns a symmetric 3×3 matrix with duration values between every pair of geographical points.
PART 4: MORE EXAMPLE API URLS
In the official documentation, you can find optional parameters that can be used for designing the MapBox Matrix API. Feel free to explore them!
- Request an asymmetric 2×3 matrix for bicycles:
- Request a 3×3 distance matrix for pedestrians:
- Request a 1×3 matrix for driving that includes both duration and distance
- Request a distance matrix for cars with a curbside approach for each destination
PART 5: LIMITATIONS
- Requests using the driving, walking, and cycling profiles can specify up to 25 input coordinates per request
- Maximum 60 request per minute can be run for the driving, walking, and cycling profiles
- Requests using the driving-traffic profile can specify up to 10 input coordinates per request
- Maximum 30 request per minute can be run for driving-traffic profile