Search API Connector Documentation

Print

Import MapBox Matrix Data to Google Sheets

CONTENTS

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.

  1. 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/
  • Profiles:
    • mapbox/driving-traffic
    • mapbox/driving
    • mapbox/walking
    • mapbox/cycling

To retrieve directions you should use the following API link:

GET https://api.mapbox.com/directions-matrix/v1/{profile}/{coordinates}?access_token=YOUR-TOKEN

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).

  1. Open up Google Sheets and click Add-ons > API Connector > Open.
  2. In the Create tab, enter the API URL constructed like this:
https://api.mapbox.com/directions-matrix/v1/mapbox/driving/-122.42,37.78;-122.45,37.91;-122.48,37.73?access_token=ENTER-YOUR-TOKEN

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:
https://api.mapbox.com/directions-matrix/v1/mapbox/cycling/-122.42,37.78;-122.45,37.91;-122.48,37.73?sources=0;2&destinations=all&access_token=YOUR-API-TOKEN
  • Request a 3×3 distance matrix for pedestrians:
https://api.mapbox.com/directions-matrix/v1/mapbox/walking/-122.418563,37.751659;-122.422969,37.75529;-122.426904,37.759617?annotations=distance&access_token=YOUR-API-TOKEN
  • Request a 1×3 matrix for driving that includes both duration and distance
https://api.mapbox.com/directions-matrix/v1/mapbox/driving/-122.418563,37.751659;-122.422969,37.75529;-122.426904,37.759617?sources=1&annotations=distance,duration&access_token=YOUR-API-TOKEN
  • Request a distance matrix for cars with a curbside approach for each destination
https://api.mapbox.com/directions-matrix/v1/mapbox/driving/-122.42,37.78;-122.45,37.91;-122.48,37.73?annotations=distance&approaches=curb;curb;curb&access_token=YOUR-API-TOKEN

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

Leave a Comment