Print

Import MapBox Data to Google Sheets

MapBox provides four different services: Maps, Navigation, Search, and Accounts. All services are accessed in a similar way, but this tutorial focuses on the Mapbox Navigation API. It shows how to fetch data directly into Google Sheets using the API Connector add-on for 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

The MapBox Navigation service contains a directions API that shows you how to reach your destination. Although this API is made to pull a route on the map, a route can be pulled into Google Sheets containing the coordinates. This API can be used for calculation of optimal routes for driving, walking, and cycling, as well as turn-by-turn instructions.

  1. If you haven't already, register an account on the MapBox site. After email confirmation, you will be directed to this page which contains a default public token. Create a new private token by clicking Create a token.
  2. Name your token and select the scopes for which you'd like access, and then save it.
    MapBox-API-pic2
  3. You'll now see your token; copy it as we'll use it shortly.
    mapbox3

Part 2: Pull Mapbox API Data into Google Sheets

For this example, we'll find a cycling route between two points (-122.42, 37.78) and (-77.03, 38.91). Enter your token where it reads your_token.

  1. Open up Google Sheets and click Extensions > API Connector > Open > Create request.
  2. In the request form enter the following:
    • ApplicationCustom
    • MethodGET
    • Request URLhttps://api.mapbox.com/directions/v5/mapbox/cycling/-122.42,37.78;-77.03,38.91?access_token=your_token
  3. Create a new tab and click Set current to use that tab as your data destination.
  4. Name your request and click Run. A moment later you’ll see data populate your sheet.
mapbox-img4

Part 3: More Example URLs

The documentation contains the full array of available endpoints and parameters, but check the examples below to get started.

  • Request to access speed limit information using the max speed annotation between 3 passed pair of coordinates using the driving profile:
https://api.mapbox.com/directions/v5/mapbox/driving/-122.39636,37.79129;-122.39732,37.79283;-122.39606,37.79349?annotations=maxspeed&overview=full&geometries=geojson&access_token=YOUR-API-TOKEN
  • Request a walking route between two locations:
https://api.mapbox.com/directions/v5/mapbox/walking/-122.42,37.78;-122.92,37.18?access_token=YOUR-API-TOKEN
  • Request directions with radiuses and a polyline response through multiple waypoints:
https://api.mapbox.com/directions/v5/mapbox/driving/13.43,52.51;13.42,52.5;13.41,52.5?radiuses=40;;100&geometries=polyline6&access_token=YOUR-API-TOKEN
  • Request a route that approaches the destination on the curb of the driving side:
https://api.mapbox.com/directions/v5/mapbox/driving/13.43,52.51;13.43,52.5?approaches=unrestricted;curb&access_token=YOUR-API-TOKEN
  • Specify a departure time:
https://api.mapbox.com/directions/v5/mapbox/driving/-122.396112,37.791399;-122.433904,37.757812?access_token=YOUR-API-TOKEN&depart_at=2021-05-05T15:00
  • Specify waypoints:
https://api.mapbox.com/directions/v5/mapbox/driving/13.43,52.51;13.42,52.5;13.43,52.5?waypoints=0;2&access_token=YOUR-API-TOKEN

Part 4: API Documentation

Official API documentation: https://docs.mapbox.com/api/navigation/directions/

Leave a Comment

Jump To