Introduction

The Mapbox web services? APIs allow for programmatic access to Mapbox tools and services. Use these APIs to retrieve information about your account, upload and change resources, and use core Mapbox tools, like geocoding and directions.

This documentation provides examples of four different techniques for accessing Mapbox web services APIs:

Each library's documentation provides information on installing the library and how to use it.

This is REST API documentation: it's the most technical level of documentation for Mapbox's web services. If you're looking to use a map in an application, you probably want to use a library like Mapbox GL JS or Mapbox Mobile instead.

Reading this Documentation

This documentation is structured by API, which is a group of related functionality like Geocoding or Uploads, and then by endpoint, which is a specific method within that API that performs one action and is located at a specific URL.

Each endpoint in this documentation is described using several parts:

  • The HTTP method: includes GET, POST, PUT, PATCH, DELETE
  • The path: for instance, /geocoding/v5/{mode}/{query}.json
  • URL parameters: these are the parts of the endpoint path wrapped in brackets, like {mode} in this example.
  • Query parameters: contained in a table with an Option header, these are added to the query string part of the request.
  • A token scope, if one is required.

All URLs referenced in the documentation have the base path https://api.mapbox.com. This base path goes before the endpoint path. In this example, you'd combine https://api.mapbox.com and /geocoding/v5/{mode}/{query}.json to get the request URL https://api.mapbox.com/geocoding/v5/{mode}/{query}.json.

For this endpoint, {mode} and {query} are the URL parameters. In a request, you replace their placeholders with real values: for instance, you'd choose mapbox.places as your mode and Chester as your query, and get the URL https://api.mapbox.com/geocoding/v5/mapbox.places/Chester.json

Query parameters are added to the end of the URL with query string encoding. If you wanted to add the country query parameter to that Geocoding request, you'd the query string ?country=us to the end of the URL, producing https://api.mapbox.com/geocoding/v5/mapbox.places/Chester.json?country=us.

All endpoints require an access token?, which is provided as a query parameter. So the final geocoding request you would construct would look like https://api.mapbox.com/geocoding/v5/mapbox.places/Chester.json?country=us&access_token=pk.my-token-value The next section covers how you get and use access tokens.

https://api.mapbox.com

Access tokens

Access to Mapbox web services? requires an access token that connects API requests to your account. The example requests in this documentation don't include an access token?: you will need to supply one using the access_token query option or by specifying the token in the SDK? or library.

Your default access token is available on the right side of your Mapbox Studio home page. You can also manage and create additional tokens on your API access tokens page in Mapbox Studio?.

When creating a new access token, you have the option of adding one or more scopes. Each scope adds a different permission to the token, allowing it to be used to access restricted APIs. Throughout the documentation, we specify the scope required to access each endpoint.

Access token example

https://api.mapbox.com/{endpoint}?access_token={your_access_token}

Versioning

Each Mapbox API is versioned with a version string specified in the base URL that can be incremented independently from other APIs.

The Maps API and Directions API are the exceptions: their endpoints are prefixed with /v4/{map_id} and /v4/directions instead of putting the version after the API name. This mismatch will be fixed in the next API version.

Using the newest available API is always encouraged.

These changes are considered backwards compatible and will not require the version string to be incremented:

  • Adding properties to JSON objects.
  • Changing the number of items returned in a single listing request.
  • Changing rate limiting thresholds.
  • The structure or length of identifiers generated by the API.
  • Changing error messages.

These changes are considered backwards incompatible and will require the version string to be incremented:

  • Removing properties from JSON objects.
  • Changing an API's URL structure

In the event that certain functionality is deprecated, we will give at least 90 days notice via email. You will only receive a deprecation email if we detect you are using part of the API that is being deprecated.

Versioning example

https://api.mapbox.com/{api}/{version}

Rate limits

Mapbox APIs have rate limits that cap the number of requests that can be made against an endpoint. If you exceed a rate limit, your request will be throttled and you will receive HTTP 429 Too Many Requests responses from the API.

Header Description
x-rate-limit-interval Length of rate-limiting interval in seconds.
x-rate-limit-limit Maximum number of requests you may make in the current interval before reaching the limit.
x-rate-limit-reset Unix timestamp of when the current interval will end and the ratelimit counter is reset.

CORS

Mapbox web services? support Cross-Origin Requests with no domain restrictions. To support Internet Explorer 8 and 9, use a library that falls back to XDomainRequest, like corslite.

Retina

Mapbox supports Retina image output on all APIs that serve images. Add @2x before the file extension on a URL to request an image at double scale. For instance, a map tile that is 256×256 pixels will be 512×512 pixels with @2x, but show the same content. When displayed on a page, the image will be still sized to 256×256 pixels, but 4 pixels of the original will represent 1 pixel in screen units.

The @2x part of the URL goes before the entire format, so a URL that ends in .png would end with @2x.png as a Retina image.

The only assets that are not available at Retina scale are tilesets uploaded from TileMill? or as MBTiles?.

# a 400x200 static map
https://api.mapbox.com/v4/mapbox.dark/-76.9,38.9,5/400x200.png

# the same static map for Retina
# displays: this image will be 800x400
# pixels, but show the same content
# and look the same when scaled down
https://api.mapbox.com/v4/mapbox.dark/-76.9,38.9,5/[email protected]

HTTPS

We recommend all access to Mapbox is over HTTPS. Except for the Maps API, requests initiated over HTTP are automatically upgraded to HTTPS.

Pagination

Pagination lets you list many objects from an API by using more than one request. After receiving a page of objects, the next page can be requested using the next link relation in Link header of the response. This process can be repeated until the server sends a response without a Link header or without a next link relation, which signals the end of the collection.

Your application must use the Link header for pagination instead of constructing your own URLs as the specific URLs used for pagination may change at any time. The Python requests library, and the link-header-parser module for JavaScript can parse Link headers. Link headers follow the RFC 5988 specifications.

Pagination is supported on the Datasets, Uploads, and Styles list endpoints.

Query Parameter Description
limit The maximum number of objects to return. The API will attempt to return the requested number of objects, but receiving fewer objects does not necessarily signal the end of the collection. Receiving a response with a Link header or no next link relation is the only way to determine when you are at the end of a collection.
Link: <https://api.mapbox.com/uploads/v1/1454024795582?start=cijywvxlm004rtikohhqf99jv&limit=100>; rel="next"

Dates

Most dates and times returned by the API are represented in RFC 3339 format, which can be parsed by the JavaScript Date constructor, the Python arrow library, and many other libraries and languages.

The only exception to this rule is the Retrieve TileJSON metadata endpoint that returns created and modified properties as Unix time.

Uploads

The Mapbox Uploads API transforms geographic data into tilesets that can be used with maps and geographic applications. Given a wide variety of geospatial formats, it normalizes projections and generates tiles at multiple zoom levels to make data viewable on the web.

The upload workflow begins with a file and ends with a tileset?, or if you have invalid data, an error.

  1. Retrieve S3 credentials to stage the file
  2. Use an S3 client, like the AWS SDK, to upload a file to S3 using those credentials
  3. Create an upload using the staged file's URL
  4. Retrieve the upload's status as it is processed into a tileset
  5. Once the upload is complete, use the tileset ID like you'd use any other tileset

Limits

Type Size limit
TIFF and GeoTIFF 10 GB
MBTiles 25 GB
GeoJSON 1 GB
CSV 1 GB
KML 260 MB
GPX 260 MB
Shapefile (zipped) 260 MB

Retrieve S3 credentials

Mapbox provides an Amazon S3 bucket to stage your file while your upload is processed. Uploads must be staged in this bucket before being uploaded to your Mapbox account. You can retrieve temporary credentials from this endpoint.

The response body is a JSON object containing the following properties.

Property Description
accessKeyId AWS Access Key ID
bucket S3 bucket name
key unique key for data to be staged
secretAccessKey AWS Secret Access Key
sessionToken temporary security token
url destination URL of the file

Use these credentials to store your data in the provided bucket with the provided key using the AWS CLI or AWS SDK? of your choice. The bucket is located in AWS region us-east-1.

GET
/uploads/v1/{username}/credentials
uploads:write Token scope

Example request

curl https://api.mapbox.com/uploads/v1/{username}/credentials

Example response

{
  "accessKeyId": "{accessKeyId}",
  "bucket": "somebucket",
  "key": "hij456",
  "secretAccessKey": "{secretAccessKey}",
  "sessionToken": "{sessionToken}",
  "url": "{url}"
}

Example AWS CLI usage

Create an upload

Once you've used the temporary S3 credentials to transfer your file to Mapbox's staging bucket, you can trigger the generation of a tileset? given the file's URL and a destination tileset ID.

The request body is a JSON object containing the following properties.

Property Description
tileset the map ID to create or replace in the format username.nameoftileset
url HTTPS URL of the S3 object provided in the credential request
name
(optional)
name for the tileset

Reuse of a tileset value will replace existing data: use a random value to make sure that a new tileset is created, or check existing tilesets first.

The response body is a JSON object containing the following properties.

Property Description
complete whether the upload is complete (true) or not (false)
tileset The id of the tileset (map) that will be created or replace if upload is successful
error if null, the upload is in progress or successfully completed. Otherwise, a brief explanation of the error
id the unique identifier for the upload
name the name of the upload
modified time when the upload resource was last modified
created time when the upload resource was created
owner the unique identifier for the owner's account
progress the progress of the upload expressed as a float between 0 and 1
POST
/uploads/v1/{username}
uploads:write Token scope

Example request

curl -X POST https://api.mapbox.com/uploads/v1/{username}

Example request body

{
  "tileset": "{username}.mytileset",
  "url": "http://somebucket.s3.amazonaws.com/markers.json",
  "name": "example-markers"
}

Example response

{
  "complete": false,
  "tileset": "example.markers",
  "error": null,
  "id": "hij456",
  "name": "example-markers",
  "modified": "{timestamp}",
  "created": "{timestamp}",
  "owner": "{username}",
  "progress": 0
}

Retrieve upload status

Upload processing is fast but not immediate. Once an upload is created, you can track its status. Uploads have a progress property that will start at 0 and end at 1 when an upload is complete. If there's an error processing an upload, the error property will include an error message.

GET
/uploads/v1/{username}/{upload_id}
uploads:read Token scope

Example request

curl https://api.mapbox.com/uploads/v1/{username}/{upload_id}

Example response

{
  "complete": true,
  "tileset": "example.markers",
  "error": null,
  "id": "hij456",
  "name": "example-markers",
  "modified": "{timestamp}",
  "created": "{timestamp}",
  "owner": "{username}",
  "progress": 1
}

Retrieve recent upload statuses

You can retrieve multiple upload statuses at the same time, sorted by the most recently created. This request returns the same information as individual upload status, but for all recent uploads. The list is limited to 1MB of JSON.

This endpoint supports pagination so that you can list many uploads. Up to 100 items can be requested at a time using the limit parameter. It also supports another parameter, reverse:

Query Parameter Description
reverse List uploads in chronological order, rather than reverse chronological order.
GET
/uploads/v1/{username}
uploads:list Token scope

Example request

curl https://api.mapbox.com/uploads/v1/{username}

Example response

[{
  "complete": true,
  "tileset": "example.mbtiles",
  "error": null,
  "id": "abc123",
  "name": null,
  "modified": "2014-11-21T19:41:10.000Z",
  "created": "2014-11-21T19:41:10.000Z",
  "owner": "example",
  "progress": 1
}, {
  "complete": false,
  "tileset": "example.foo",
  "error": null,
  "id": "xyz789",
  "name": "foo",
  "modified": "2014-11-21T19:41:10.000Z",
  "created": "2014-11-21T19:41:10.000Z",
  "owner": "example",
  "progress": 0
}]

Remove an upload

Remove a completed upload status from the upload listing.

Uploads are only statuses: removing an upload from the listing doesn't delete the associated tileset?. Tilesets can only be deleted from within Mapbox Studio?. An upload cannot be removed until it is completed.

DELETE
/uploads/v1/{username}/{upload_id}
uploads:write Token scope

Example request

$ curl -X DELETE https://api.mapbox.com/uploads/v1/{username}/{upload_id}

Example response

HTTP 204

Styles

The Mapbox Styles API lets you read and change map styles, fonts, and icons. This API is the basis for Mapbox Studio, our cartography software.

If you use Studio, Mapbox GL JS or the Mapbox Mobile SDKs, you're already using the Styles API. This documentation is geared toward software developers who want to programmatically read & write these resources: it isn't necessary to read or understand this reference to design or use maps.

You'll want to be familiar with the Mapbox GL Style Spec to use this API: it defines the structure of map styles and is the open standard that helps Studio communicate with APIs and produce maps compatible with our libraries (like GL JS and Mobile). When we refer to style objects, they are objects that fit the Mapbox GL? Style Spec. You can see examples of these styles in our mapbox-gl-styles project, or you can create a new style? using Mapbox Studio.

Limits

  • Styles cannot reference more than 15 sources.
  • Styles cannot be larger than 5MB. This limit only applies to the style document itself, not the sprites, fonts, tilesets, or other resources it references.
  • The number of styles allowed per account varies based on plan level.

Mapbox styles

The following styles are available to all accounts using a valid access token?:

The style object

The style object conforms to the Mapbox GL Style Specification, with these additional account-related properties:

Property Description
metadata information about the style that is used in Mapbox Studio
created date and time the style was created
id id of the style
modified date and time the style was last modified
owner the username of the style owner
draft whether the style is draft or published
{
  "version": 8,
  "name": "{name}",
  "metadata": "{metadata}",
  "sources": {},
  "sprite": "mapbox://sprites/{username}/{style_id}",
  "glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
  "layers": ["{layers}"],
  "created": "2015-10-30T22:18:31.111Z",
  "id": "{style_id}",
  "modified": "2015-10-30T22:22:06.077Z",
  "owner": "{username}",
  "draft": true
}

Retrieve a style

Retrieve a style? as a JSON document. The returned style object will be in the Mapbox GL Style Spec format.

GET
/styles/v1/{username}/{style_id}
styles:read Token scope

Example request

curl https://api.mapbox.com/styles/v1/{username}/{style_id}

Example response

{
  "version": 8,
  "name": "My Awesome Style",
  "metadata": { },
  "sources": {
    "myvectorsource": {
      "url": "mapbox://{map_id}",
      "type": "vector"
    },
    "myrastersource": {
      "url": "mapbox://{map_id}",
      "type": "raster"
    }
  },
  "sprite": "mapbox://sprites/{username}/{style_id}",
  "glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
  "layers": [ ],
  "created": "2015-10-30T22:18:31.111Z",
  "id": "{style_id}",
  "modified": "2015-10-30T22:22:06.077Z",
  "owner": "{username}",
  "draft": true
}

List styles

Retrieve a list of styles for an account. This endpoint does not return full styles, but returns style? metadata.

GET
/styles/v1/{username}
styles:read Token scope

Example request

curl https://api.mapbox.com/styles/v1/{username}

Example response

[
  {
    "version": 8,
    "name": "My Awesome Style",
    "created": "{timestamp}",
    "id": "cige81msw000acnm7tvsnxcp5",
    "modified": "{timestamp}",
    "owner": "{username}"
  },
  {
    "version": 8,
    "name": "My Cool Style",
    "created": "{timestamp}",
    "id": "cig9rvfe300009lj9kekr0tm2",
    "modified": "{timestamp}",
    "owner": "{username}"
  }
]

Create a style

Creates a style? in your account. The posted style object must be both valid JSON and aligned to the Mapbox GL Style Spec: invalid styles will produce a descriptive validation error.

Only the most recent version of the Mapbox GL? Style Spec is supported. If the optional "name" property is omitted, it will be automatically set to the style's ID.

The style you get back from the API will have new properties that the server has added: created, id, modified, owner, and draft.

POST
/styles/v1/{username}
styles:write Token scope

Example request

# assuming that you have a valid style named basic-v8.json
curl -X POST https://api.mapbox.com/styles/v1/{username} \
  --data @basic-v8.json \
  --header "Content-Type:application/json"

Example request body

{
  "version": 8,
  "name": "My Awesome Style",
  "metadata": { },
  "sources": {
    "myvectorsource": {
      "url": "mapbox://{map_id}",
      "type": "vector"
    },
    "myrastersource": {
      "url": "mapbox://{map_id}",
      "type": "raster"
    }
  },
  "glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
  "layers": [ ]
}

Example response

{
  "version": 8,
  "name": "My Awesome Style",
  "metadata": { },
  "sources": {
    "myvectorsource": {
      "url": "mapbox://{map_id}",
      "type": "vector"
    },
    "myrastersource": {
      "url": "mapbox://{map_id}",
      "type": "raster"
    }
  },
  "sprite": "mapbox://sprites/{username}/{style_id}",
  "glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
  "layers": [ ],
  "created": "2015-10-30T22:18:31.111Z",
  "id": "{style_id}",
  "modified": "2015-10-30T22:22:06.077Z",
  "owner": "{username}",
  "draft": true
}

Update a style

Updates an existing style? in your account with new content.

Requesting a style and then using the same content to update the style will fail: you'll need to remove the created and modified properties before updating a style. The name property, which is optional for style creation, is required when updating a style. Cross-version PATCH requests are rejected.

PATCH
/styles/v1/{username}/{style_id}
styles:write Token scope

Example request

curl -X PATCH "https://api.mapbox.com/styles/v1/{username}/{style_id} \
  --data @basic-v8.json \
  --header "Content-Type:application/json"

Example request body

{
  "version": 8,
  "name": "New Style Name",
  "metadata": { },
  "sources": { },
  "sprite": "mapbox://sprites/{username}/{style_id}",
  "glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
  "layers": [{
    "id": "new-layer",
    "type": "background",
    "paint": {
      "background-color": "#111"
    },
    "interactive": true
  }],
  "created": "2015-10-30T22:18:31.111Z",
  "id": "{style_id}",
  "modified": "2015-10-30T22:22:06.077Z",
  "owner": "{username}",
  "draft": true
}

Example response

{
  "version": 8,
  "name": "New Style Name",
  "metadata": { },
  "sources": { },
  "sprite": "mapbox://sprites/{username}/{style_id}",
  "glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
  "layers": [{
    "id": "new-layer",
    "type": "background",
    "paint": {
      "background-color": "#111"
    },
    "interactive": true
  }],
  "created": "2015-10-30T22:18:31.111Z",
  "id": "{style_id}",
  "modified": "2015-10-30T22:22:06.077Z",
  "owner": "{username}",
  "draft": true
}

Delete a style

Deletes a style?. All sprites that belong to this style will also be deleted and the style will no longer be available.

DELETE
/styles/v1/{username}/{style_id}
styles:write Token scope

Example request

curl -X DELETE https://api.mapbox.com/styles/v1/{username}/{style_id}

Response

HTTP 204

Fonts

Two types of fonts are supported: TrueType fonts, usually with .ttf file extensions, and OpenType fonts, with .otf extensions. The API accepts fonts as raw binary data, allows those fonts to be deleted, and generates encoded letters for map renderers.

Fonts are managed on a per-account basis: styles can use any font from the same account.

Font limits

  • Fonts must be smaller than 30MB.
  • Accounts are limited to 100 fonts.

Retrieve font glyph ranges

Glyph ranges are usually not of interest unless you're building a map renderer, but this is the endpoint where you can access them.

Font glyph ranges are protocol buffer-encoded signed distance fields. They can be used to show fonts at a variety of scales and rotations. One glyph is used at all scales.

URL Parameter Description
font name of the font, can be multiple comma-separated font names
start A multiple of 256 between 0 and 65280
end start + 255
GET
/fonts/v1/{username}/{font},{font}/{start}-{end}.pbf
fonts:read Token scope

Example request

curl https://api.mapbox.com/fonts/v1/{username}/{font},{font}/{start}-{end}.pbf

Response

A successful request will return HTTP 200 Success. The response body will be a buffer of the glyphs with Content-Type: application/x-protobuf.

Sprites

Sprites are the way that Mapbox GL JS? and Mapbox Mobile efficiently request and show icons. They are collections of icons that can be used in styles as markers or patterns in symbol layers. Icons are SVG? images that can be added and removed at will. The Styles API automatically collects these SVG images and renders them into a single PNG image and a JSON document that describes where each icon is positioned.

The sprite? JSON document is specified as part of the the Mapbox GL Style Spec.

Sprites are managed on a per-style basis: each sprite belongs to a style, so the sprite limit of 100 icons is also a per-style limit. All sprite-related API methods will require a {style_id} parameter referring to the style? that sprite belongs to.

Sprite limits

  • Each icon must be smaller than 400kB.
  • Mapbox supports most, but not all SVG properties. Our SVG troubleshooting document describes these limits.
  • Icons can be up to 512px in each dimension.
  • Sprites can contain up to 100 icons.

Retrieve a sprite image or JSON

Retrieves a sprite? image or JSON document.

URL Parameter Description
@2x
(optional)
Render sprite at 2x resolution, appropriate for high-density displays
format
(optional)
.png for the sprite image, or .json for the document. Without a format specified, JSON will be returned.
GET
/styles/v1/{username}/{style_id}/sprite[@2x].{format}
styles:read Token scope

Example request

# requesting retina json
curl https://api.mapbox.com/styles/v1/{username}/{style_id}/sprite@2x

# requesting normal-resolution png
curl https://api.mapbox.com/styles/v1/{username}/{style_id}/sprite.png

Example response

{
  "default_marker": {
    "width": 20,
    "height": 50,
    "x": 0,
    "y": 0,
    "pixelRatio": 2
  },
  "secondary_marker": {
    "width": 20,
    "height": 50,
    "x": 20,
    "y": 0,
    "pixelRatio": 2
  }
}

Add new icon to sprite

Adds a new icon to an existing sprite?.

The request body should be raw SVG? data.

PUT
/styles/v1/{username}/{style_id}/sprite/{icon_name}
styles:write Token scope

Example request

curl -X PUT \
  https://api.mapbox.com/styles/v1/{username}/{style_id}/sprite/{icon_name} \
  --data @aerialway-12.svg

Example response

{
  "newsprite": {
    "width": 1200,
    "height": 600,
    "x": 0,
    "y": 0,
    "pixelRatio": 1
  },
  "default_marker": {
    "width": 20,
    "height": 50,
    "x": 0,
    "y": 600,
    "pixelRatio": 1
  }
}

Delete icon from sprite

Deletes an icon from an existing sprite?.

DELETE
/styles/v1/{username}/{style_id}/sprite/{icon_name}
styles:write Token scope

Example request

curl -X DELETE /styles/v1/{username}/{style_id}/sprite/{icon_name}

Example response

{
  "default_marker": {
    "width": 20,
    "height": 50,
    "x": 0,
    "y": 600,
    "pixelRatio": 1
  },
  "secondary_marker": {
    "width": 20,
    "height": 50,
    "x": 20,
    "y": 600,
    "pixelRatio": 1
  }
}

Embed a style

Request embeddable HTML suitable for fullscreen map displays or for inserting into blog posts and articles as <iframe> content.

Query Parameter Description
zoomwheel
(optional)
Disables zooming with mouse scroll wheel (default true)
title
(optional)
If true , shows a title box in upper right corner with map title and owner (default false )

Embed request format

GET
/styles/v1/{username}/{style_id}.html
styles:read Token scope

Example style embed

<iframe
  src='https://api.mapbox.com/styles/v1/mapbox/streets-v8.html?title=true&zoomwheel=true' />

Maps

The Mapbox Maps API supports reading raster tilesets, vector tilesets, and Mapbox Editor? project features. Tilesets can be retrieved as images, TileJSON, or HTML slippy maps for embedding. Mapbox Editor project features can be retrieved as GeoJSON? or KML?.

If you use Mapbox.js, Mapbox GL JS, or another library like Leaflet, you're already using this API. This documentation is geared toward software developers who want to programmatically read these resources: it isn't necessary to read or understand this reference to design or use maps.

Mapbox classic map IDs

The following map IDs are accessible to all accounts using a valid access token?:

Retrieve tiles

Returns a image tile, vector tile, or UTFGrid in the specified format.

URL Parameter Description
map_id unique identifier for the tileset in format username.id
format return format; .grid.json for UTFGrid, .vector.pbf for vector tile, or an image extension listed below

The {z}/{x}/{y} parameters are the tile coordinates as described in the Slippy Map Tilenames specification: they specify the tile's zoom level {z} and column {x} and row {y}.

The format of any image request can be replaced by any of the following formats to adjust image quality for different bandwidth requirements. Higher-compression formats like jpg70 or png32 can be useful to favor performance over image quality.

Image format Description
png32 32 color indexed PNG
png64 64 color indexed PNG
png128 128 color indexed PNG
png256 256 color indexed PNG
jpg70 70% quality JPG
jpg80 80% quality JPG
jpg90 90% quality JPG

You can prefix the format with @2x to request a high DPI version. The @2x is placed after the {z}/{x}/{y} and before the ., like 1/0/[email protected]

The response is an image tile in the specified format. For performance, image tiles are delivered with a max-age header value set 12 hours in the future.

GET
/v4/{map_id}/{z}/{x}/{y}{@2x}.{format}

Example request

$ curl https://api.mapbox.com/v4/mapbox.streets/1/0/0.png

# a 2x tile: this is a 512x512 tile appropriate
# for high-density displays like Retina displays
$ curl https://api.mapbox.com/v4/mapbox.streets/1/0/[email protected]

# this requests a UTFGrid useful for interactivity
$ curl https://api.mapbox.com/v4/my.tileset/1/0/0.grid.json

Retrieve an HTML slippy map

Returns an HTML slippy map for sharing or embedding.

URL Parameter Description
options
(optional)
a comma-separated list of controls and map behaviors to be included in the map
hash
(optional)
a zoom level and location for the map in format #{zoom}/{lat}/{lon}
Query Parameter Description
zoomwheel enable zooming with the mouse wheel
zoompan enable zoom and pan controls
geocoder add a geocoder control
share add a share control

The response is HTML of a slippy map.

GET
/v4/{map_id}{/options}.html{hash}

Example request

# a map with zoom controls, mouse controls, a geocoder, and share
$ curl https://api.mapbox.com/v4/mapbox.light/zoomwheel,zoompan,geocoder,share.html

# the same map without any options
$ curl https://api.mapbox.com/v4/mapbox.light.html

Retrieve features from Mapbox Editor projects

Retrieve vector features from Mapbox Editor? projects as GeoJSON? or KML?. GeoJSON returns a FeatureCollection with features that conform to the simplestyle-spec.

URL Parameter Description
format json for GeoJSON, kml for KML
GET
/v4/{map_id}/features.{format}

Example request

$ curl https://api.mapbox.com/v4/mapbox.dc-markers/features.json

# or the same dataset as KML
$ curl https://api.mapbox.com/v4/mapbox.dc-markers/features.kml

Example response

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "id": "{marker_id}",
        "title": "{title}",
        "description": "{description}",
        "marker-size": "{simplestyle size}",
        "marker-color": "{simplestyle color}",
        "marker-symbol": "{maki symbol}"
      },
      "geometry": {
        "coordinates": [ -77.031952, 38.913184 ],
        "type": "Point"
      },
      "id": "{feature_id}"
    }
  ]
}

Retrieve features from vector tiles

Retrieve data about specific vector features at a specified location within a vector tileset?. The response body is a GeoJSON? FeatureCollection of features at or near the geographic point described by {lon},{lat} and within the distance described by the radius parameter. The geometry of the feature is not returned.

Query Parameter Description
radius
(optional)
Approximate distance in meters to query for features. Defaults to 0 .
limit
(optional)
Number of features between 1-50 to return. Defaults to 5 .

The radius parameter has no upper bound and is required for queries against point and line data. Due to the nature of tile buffering, a query with a large radius made against equally large point or line data may not include all possible features in the results.

Restrictions and limits

Use of this endpoint is rate limited to 600 requests per minute. For a higher rate limit, contact us.

Exceeding the limits above will result in an HTTP 429 response. For information on rate limit headers, see Rate limits.

The original geometry of the result features will not be returned in the resultset. The geometry type in the response will be Point for all features returned in the FeatureCollection:

  • For Polygon and MultiPolygon features the geometry is the point at the queried lon,lat
  • For LineString and MultiLineString features the geometry is the nearest point on the feature within the radius threshold of lon,lat
  • For Point and MultiPoint features the geometry is the nearest point within the radius threshold of lon,lat

Features in the response body will include a tilequery object with the following additional properties:

Property Description
distance Approximate distance in meters from the feature result to the queried point.
layer The vector tile layer of the feature result.
GET
/v4/{map_id}/tilequery/{lon},{lat}.json

Example request

$ curl https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/tilequery/-122.42901,37.80633.json?radius=10

Example response

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -122.42901,
          37.80633
        ]
      },
      "properties": {
        "class": "national_park",
        "type": "national_park",
        "tilequery": {
          "distance": 0,
          "layer": "landuse_overlay"
        }
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -122.42899060249329,
          37.80628209004094
        ]
      },
      "properties": {
        "localrank": 1,
        "maki": "park",
        "name": "Fort Mason",
        "name_de": "Fort Mason",
        "name_en": "Fort Mason",
        "name_es": "Fort Mason",
        "name_fr": "Fort Mason",
        "name_ru": "Fort Mason",
        "name_zh": "Fort Mason",
        "ref": "",
        "scalerank": 1,
        "type": "National Park",
        "tilequery": {
          "distance": 7,
          "layer": "poi_label"
        }
      }
    }
  ]
}

Retrieve TileJSON metadata

Returns TileJSON metadata for a tileset?. This is an object that describes a map's resources, like tiles, markers, and UTFGrid, as well as its name, description, and centerpoint.

Query Parameter Description
?secure
(optional)
request resources in the response as HTTPS endpoints
GET
/v4/{map_id}.json

Example request

$ curl https://api.mapbox.com/v4/mapbox.emerald.json

# the same request with HTTPS endpoints
$ curl https://api.mapbox.com/v4/mapbox.emerald.json?secure

Example response

{
  "attribution": "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">&copy; Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">&copy; OpenStreetMap</a> <a class=\"mapbox-improve-map\" href=\"https://www.mapbox.com/map-feedback/\" target=\"_blank\">Improve this map</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">&copy; DigitalGlobe</a>",
  "autoscale": true,
  "bounds": [-180, -85, 180, 85],
  "cacheControl": "max-age=43200,s-maxage=604800",
  "center": [0, 0, 3],
  "created": 1358310600000,
  "description": "",
  "id": "mapbox.satellite",
  "maxzoom": 19,
  "minzoom": 0,
  "modified": 1446150592060,
  "name": "Mapbox Satellite",
  "private": false,
  "scheme": "xyz",
  "tilejson": "2.0.0",
  "tiles": [
    "http://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png",
    "http://b.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png"
  ],
  "webpage": "http://a.tiles.mapbox.com/v4/mapbox.satellite/page.html"
}

Static

The Mapbox Static API returns static maps and raster tiles from styles in the Mapbox GL Style Spec.

Static maps are standalone images that can be displayed on web and mobile devices without the aid of a mapping library or API. They look like an embedded map without interactivity or controls.

Raster tiles can be used in traditional web mapping libraries like Mapbox.js, Leaflet, OpenLayers, and others.

Retrieve a static map from a style

In contrast to the legacy Static API, this API supports pitch, bearing, and decimal zoom levels.

The position of the map is represented by 5 numbers: longitude, latitude, zoom, bearing, and pitch. The last two numbers, bearing and pitch, are optional: if you only specify bearing and not pitch, pitch will default to 0. If you specify neither, they will both default to 0.

URL Parameter Description
lon longitude for the center point of the static map; number between -180 and 180
lat latitude for the center point of the static map; number between -90 and 90
zoom zoom level; number between 0 and 22 . Fractional zoom levels will be rounded to two decimal places.
bearing
(optional)
bearing: rotates the map around its center. number between 0 and 360 , interpreted as decimal degrees. 90 rotates the map 90° to the left. 180 flips the map. Defaults to 0 .
pitch
(optional)
pitch: tilts the map, producing a perspective effect. number between 0 and 60 . Defaults to 0 .
width width of the image; number between 1 and 1280
height height of the image; number between 1 and 1280
@2x
(optional)
If @2x is added to request a retina 2x image will be returned
Query Parameter Description
attribution
(optional)
boolean value controlling whether there is attribution on the image; defaults to true
logo
(optional)
boolean value controlling whether there is a Mapbox logo on the image; defaults to true
GET
/styles/v1/{username}/{style_id}/static/{lon},{lat},{zoom},{bearing},{pitch}/{width}x{height}{@2x}
styles:tiles Token scope

Example Request

# retrieve a map at -122.4241 longitude, 37.78 latitude,
# zoom 14.24, bearing 0, and pitch 60. The map
# will be 600 pixels wide and 600 pixels high
curl https://api.mapbox.com/styles/v1/mapbox/streets-v8/static/-122.4241,37.78,14.25,0,60/600x600

# retrieve a map at 0 longitude, 10 latitude, zoom 3,
# and bearing 20. Pitch will default to 0.
curl https://api.mapbox.com/styles/v1/mapbox/streets-v8/static/0,20,3,20/600x600

# retrieve a map at 0 longitude, 0 latitude, zoom 2.
# bearing & pitch default to 0.
curl https://api.mapbox.com/styles/v1/mapbox/streets-v8/static/0,0,2/600x600

Retrieve raster tiles from styles

Request 512x512 image tiles from a style? that can be arranged and displayed with the help of a mapping library. Normally, you will not need to interact with this API directly, as our SDKs handle this for you.

Note that these image tiles will be offset by 1 zoom level when compared to traditional 256x256 tiles (for example, 512x512 tiles at zoom level 4 are equivalent to traditional tiles at zoom level 5). Tiles are 512px by 512px unless the @2x parameter is included, in which case they're scaled to 1024px by 1024px.

GET
/styles/v1/{username}/{style_id}/tiles/{z}/{x}/{y}{@2x}

Example request

curl https://api.mapbox.com/styles/v1/mapbox/streets-v8/tiles/1/1/0

Static (Classic)

The classic Mapbox Static API lets you request static maps from tilesets, with the option to add vector data as overlays. Static maps are standalone images that can be displayed on web and mobile devices without the aid of a mapping library or API. They look like an embedded map without any interactivity or controls.

If you've uploaded data to Mapbox, you've already seen the classic Static API in action, powering the images at the top of all tileset? detail pages.

Limits

  • The maximum size for a static map image is 1280x1280 pixels.

  • The URL for a request to this API cannot be longer than 4096 characters.

  • Overlays cannot consist of more than 100 features.

  • Markers must be less 8192 pixels.

  • Static map images give you design flexibility in how you want to display map attribution. When using Static maps it is your responsibility to add proper attribution for maps in your website or application.

Retrieve a static map image

URL Parameter Description
map_id unique identifier for the tileset in format username.id . These can be a comma-separated list of IDs.
overlay
(optional)
one or more comma-separated features to draw on top of the map. These can be in marker , geojson or path format.
position center and zoom level for the map. You can use auto to automatically fit image to overlay features, or {lon},{lat},{zoom} to set a specific location and zoom
width width of the image in pixels
height height of the image in pixels
format format of the image

The support formats are the same as for the Mapbox Maps API:

Image format Description
png32 32 color indexed PNG
png64 64 color indexed PNG
png128 128 color indexed PNG
png256 256 color indexed PNG
jpg70 70% quality JPG
jpg80 80% quality JPG
jpg90 90% quality JPG

The {overlay} parameter can specify one or more features to draw on top of the map. The list of features should be comma-separated. Each overlay feature can be in one of three formats: marker, geojson or path.

Marker

{name}-{label}+{color}({lon},{lat})
URL Parameter Description
name Marker shape and size. Options are pin-s , pin-m , pin-l .
label
(optional)
Marker symbol. Options are an alphanumeric label a through z , 0 through 99 , or a valid Maki icon.
color
(optional)
A 3- or 6-digit hexadecimal color code.

Custom marker

url-{url}({lon},{lat})
URL Parameter Description
url a percent-encoded URL for the image

Custom markers are cached according to the Expires and Cache-Control headers. Make sure that at least one of these headers is set to an proper value to prevent repeated requests for the custom marker image.

The marker image is always centered on the specified location. When creating an asymmetric marker like a pin, make sure that the tip of the pin is at the center of the image.

GeoJSON

geojson({geojson})

The {geojson} argument must be a valid GeoJSON object. simplestyle-spec styles for GeoJSON? features will be respected and rendered.

URL Parameter Description
geojson a valid GeoJSON object. simplestyle-spec styles for

GeoJSON features will be respected and rendered.

Path

path-{strokecolor}-{strokeopacity}+{fillcolor}-{fillopacity}({polyline})

Encoded polylines can be used with the Static API via the path parameter.

URL Parameter Description
strokecolor
(optional)
A 3- or 6-digit hexadecimal color code for the line stroke
strokeopacity
(optional)
A number between 0 (transparent) and 1 (opaque) for line stroke opacity
fillcolor
(optional)
A 3- or 6-digit hexadecimal color code for the fill
fillopacity
(optional)
A number between 0 (transparent) and 1 (opaque) for fill opacity
polyline A valid encoded polyline encoded as a URI component
GET
/v4/{map_id}/{overlay}/{position}/{width}x{height}{@2x}.{format}

Example Request

# without an overlay
curl https://api.mapbox.com/v4/mapbox.dark/-76.9,38.9,5/1000x1000.png

# with a custom marker overlay
curl https://api.mapbox.com/v4/mapbox.dark/url-https%3A%2F%2Fmapbox.com%2Fimg%2Frocket.png(-76.9,38.9)/-76.9,38.9,15/1000x1000.png

# with a polyline overlay
curl https://api.mapbox.com/v4/mapbox.streets/path-5+f44-0.5+f44-0.2(kumwFrjvbMaf%40kuD%7BnCkS)/-73.99,40.70,12/500x300.png

Retrieve a standalone marker

Request a single marker image without any background map.

URL Parameter Description
name Marker shape and size. Options are pin-s , pin-m , pin-l .
label
(optional)
a valid Maki icon name.
color
(optional)
A 3- or 6-digit hexadecimal color code. Default is gray.
@2x
(optional)
Include to request a high DPI version of the image.
GET
/v4/marker/{name}-{label}+{color}{@2x}.png

Example request

curl https://api.mapbox.com/v4/marker/pin-s[email protected]

# a default gray marker
curl https://api.mapbox.com/v4/marker/pin-m.png

# a medium blue marker labeled A
curl https://api.mapbox.com/v4/marker/pin-m-1+00f.png

Directions

The Mapbox Directions API will show you how to get where you're going. Routing is fundamental to business logistics and consumer applications. With the Directions API, you can:

  • calculate optimal driving, walking, and cycling routes
  • produce turn-by-turn directions
  • produce routes with up to 25 waypoints anywhere on earth

This API supports three different routing profiles:

  • mapbox.driving for car and motorcycle routing. This profile shows the fastest routes by preferring high-speed roads like highways.
  • mapbox.walking for pedestrian and hiking routing. This profile shows the shortest path by using sidewalks and trails.
  • mapbox.cycling for bicycle routing. This profile shows routes that are short and safer for cyclist, avoiding highways and preferring streets with bike lanes.

Retrieve directions

Retrieve directions between waypoints. This can include both the route's geometry and instructions for each turn.

URL Parameter Description
profile routing profile; either mapbox.driving , mapbox.walking , or mapbox.cycling
waypoints a semicolon-separated list of {longitude},{latitude} coordinate pairs to visit in order, containing at least two elements (origin and destination). There can be anywhere between 2 and 25 coordinate pairs in the list.
Query Parameter Description
alternatives
(optional)
whether to generate alternative routes; can be true or false
instructions
(optional)
format to return route instructions; can be text (default) or html
geometry
(optional)
format to return route geometry; can be geojson (default), polyline for an encoded polyline, or false to omit geometry from response
steps
(optional)
whether to include steps in response; can be true or false

Polylines are encoded with a precision level of 6: be sure to configure your decoding library to use 6 precision. Polyline decoding libraries exist for JavaScript, Swift, Ruby, and many other languages.

The response to a directions request is a JSON object with the following properties:

  • origin: a GeoJSON Feature with a Point geometry type representing the starting point of the route. Must have a name property, but more properties are also acceptable.
  • destination: as above, but representing the final destination of the route.
  • waypoints: an array of GeoJSON Feature Objects, as above, representing intermediate waypoints.
  • routes: an array containing the recommended (fastest) route and, at most, one alternative route. Each element is a JSON object with the following properties:

    • distance: the distance of the route in meters
    • duration: the estimated travel time in seconds
    • summary: a short, human-readable summary of of the route
    • geometry: the geometry of the route as either a GeoJSON LineString or encoded polyline with precision 6
    • steps: an array of route steps -- maneuvers like turns or merges followed by a distance of travel to the next step. Each element is a JSON object with the following properties:

      • distance: the distance to the next maneuver in meters
      • duration: the estimated travel time to the next maneuver in seconds
      • way_name: the road or path the maneuver is on
      • direction: the rough cardinal direction of travel following the maneuver ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', or 'NW')
      • heading: the clockwise angle from true north to the direction of travel following the maneuver
      • maneuver: a JSON object representing the maneuver with the following properties:

        • type: the type of maneuver; one of: continue, bear right, turn right, sharp right, u-turn, sharp left, turn left, bear left, waypoint, depart, enter roundabout, and arrive. New maneuver types may be introduced in the future without an API version change.
        • location: a GeoJSON Point geometry where the maneuver is located.
        • instruction: human-readable text or HTML describing the maneuver. See the instructions parameter above.
        • mode: the mode of transportation. Possible values as follows:

          • For driving: driving, ferry, movable bridge, unaccessible
          • For walking: walking, ferry, unaccessible
          • For cycling: cycling, walking, ferry, train, moveable bridge, unaccessible
GET
/v4/directions/{profile}/{waypoints}.json

Example request

curl https://api.mapbox.com/v4/directions/mapbox.driving/-122.42,37.78;-77.03,38.91.json

Example response

{
  "origin": {
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [-122.42001342773438, 37.780094146728516]
    },
    "properties": {"name": "McAllister Street"}
  },
  "destination": {
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [-122.41999816894531, 37.77000045776367]
    },
    "properties": {"name": "Duboce Avenue"}
  },
  "waypoints": [],
  "routes": [
    {
      "distance": 1239,
      "duration": 111,
      "summary": "Van Ness Avenue (US 101) - Otis Street",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [-122.420017, 37.780096],
          [-122.42016, 37.780081],
          [-122.420324, 37.780074],
          [-122.420197, 37.770403],
          [-122.420184, 37.770132],
          [-122.42018, 37.769996],
          [-122.419998, 37.77]
        ]
      },
      "steps": [
        {
          "maneuver": {
            "type": "depart",
            "location": {
              "type": "Point",
              "coordinates": [-122.420017, 37.780096]
            },
            "instruction": "Head west on McAllister Street"
          },
          "distance": 28,
          "duration": 9,
          "way_name": "McAllister Street",
          "direction": "W",
          "heading": 268,
          "mode": "driving"
        },
        {
          "maneuver": {
            "type": "bear right",
            "location": {
              "type": "Point",
              "coordinates": [-122.418702, 37.773081]
            },
            "instruction": "Bear right onto Otis Street"
          },
          "distance": 358,
          "duration": 24,
          "way_name": "Otis Street",
          "direction": "SW",
          "heading": 223,
          "mode": "driving"
        },
        {
          "maneuver": {
            "type": "arrive",
            "location": {
              "type": "Point",
              "coordinates": [-122.419998, 37.77]
            },
            "instruction": "You have arrived at your destination"
          }
        }
      ]
    }
  ]
}

Map Matching

The Mapbox Map Matching API snaps fuzzy, inaccurate traces from a GPS unit or a phone to the OpenStreetMap? road and path network using the Directions API. This produces clean paths that can be displayed on a map or used for other analysis.

Limits

  • Maximum 60 requests per minute
  • Maximum 100 coordinates per request
  • Results must be displayed on a Mapbox map using one of our libraries or SDKs

For high volume or other use cases, contact us.

Retrieve a match

Returns a path on the road and path network closest to the input traces.

URL Parameter Description
profile A directions profile ID; either mapbox.driving , mapbox.walking , or mapbox.cycling
Query Parameter Description
geometry
(optional)
Format of the returned geometry. Allowed values are: geojson (default, as LineString ), polyline ( documentation ) with precision 6, false (no geometry, but matched points )
gps_precision
(optional)
An integer in meters indicating the assumed precision of the used tracking device. Use higher numbers (5-10) for noisy traces and lower numbers (1-3) for clean traces. The default value is 4.

Request body must be one GeoJSON Feature with a LineString geometry. The LineString may have up to 100 positions.

If your traces are in GPX or KML format, you can use toGeoJSON to transform them to GeoJSON?.

Property Description
coordTimes
(optional)
an array of timestamps corresponding to positions in the LineString; can be numbers in Unix time (seconds since the Unix epoch) or strings in RFC 3339 format.

It is recommended to include timestamps, since they help improve the quality of the matching. The timestamps must be ascending. For best results, your timestamps should have a sample rate of about 5 seconds.

Some pre-processing tips to achieve the best results:

  • The Map Matching API is limited to processing traces with up to 100 coordinates. If you need to process longer traces, you can split the trace and make multiple requests.
  • Clusters of points (like a person waiting at a train crossing for a few minutes) often don't add more information to a trace and should be removed.
  • Map matching works best with a sample rate of 5 seconds between points. If your trace has a higher sample rate, you may want to downsample your trace.
  • geojson-tidy removes clusters and re-samples traces, which can be useful for preprocessing.

The response is a GeoJSON FeatureCollection aligned with the OpenStreetMap? road/path network. It may include one or more GeoJSON Features; on clean matches, only one feature is returned, but when the matching algorithm cannot decide the correct match between two points, it will omit that line and create several sub-matches, each as a feature. The higher the number of features, the more likely that the input traces are poorly aligned to the road network.

Property Description
code a string depicting the state of the response; see below for options
geometry geometry type for returned line; will be a GeoJSON LineString. If geometry option in request was set to polyline , will be an encoded polyline
confidence a number between 0 (low) and 1 (high) indicating level of confidence in match
distance the total distance traveled in the matching in meters
duration the expected travel time in the matching in seconds
matchedPoints an array of coordinate pairs denoting the location an input point was matched with
indices a list of indices connecting matchedPoints with input points

All routing responses will include a code property that describes the type of result. If a server error occurs, the HTTP status code will be 500 or higher and the response will not include a code property.

Code option Description
Ok Normal case
NoMatch The input did not produce any matches. features will be an empty array.
TooManyCoordinates There are more than 100 points in the request.
InvalidInput message will hold an explanation of the invalid input.
ProfileNotFound Profile should be mapbox.driving , mapbox.walking , or mapbox.cycling .
POST
/matching/v4/{profile}.json

Example request

$ curl -X POST \
  --header "Content-Type:application/json" \
  -d @trace.json \
  https://api.mapbox.com/matching/v4/mapbox.driving.json

Example request body

{
  "type": "Feature",
  "properties": {
    "coordTimes": [
      "2015-04-21T06:00:00Z",
      "2015-04-21T06:00:05Z",
      "2015-04-21T06:00:10Z",
      "2015-04-21T06:00:15Z",
      "2015-04-21T06:00:20Z"
    ]
    },
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [13.418946862220764, 52.50055852688439],
      [13.419011235237122, 52.50113000479732],
      [13.419756889343262, 52.50171780290061],
      [13.419885635375975, 52.50237416816131],
      [13.420631289482117, 52.50294888790448]
    ]
  }
}

Example response

{
  "code": "Ok",
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [13.418805, 52.500599],
          [13.418851, 52.500659],
          [13.419145, 52.501095],
          [13.419276, 52.501286],
          [13.419618, 52.501754],
          [13.419981, 52.502249],
          [13.420042, 52.502335],
          [13.420494, 52.502984]
        ]
      },
      "properties": {
        "confidence": 0.8165256193474186,
        "distance": 120,
        "duration": 31,
        "matchedPoints": [
          [13.418805122375488, 52.50059890747071],
          [13.419144630432129, 52.50109481811523],
          [13.419617652893066, 52.50175094604492],
          [13.420042037963867, 52.50233459472656],
          [13.420494079589844, 52.50298309326172]
        ],
        "indices": [0, 1, 2, 3, 4]
      }
    }
  ]
}

Geocoding

The Mapbox Geocoding API does two things: geocoding and reverse geocoding.

Geocoding lets you convert location text into geographic coordinates: turning 1600 Pennsylvania Ave NW into -77.0366, 38.8971.

Reverse geocoding turns geographic coordinates into place names: from -77.036, 38.897 to 1600 Pennsylvania Ave NW. These place names can vary from specific addresses to states and countries that contain the given coordinate.

Restrictions and limits

Use of the geocoding API is rate limited by access token?. These limits vary by plan.

Account level Rate limit
Starter 600 requests per minute
Standard 600 requests per minute
Premium 600 requests per minute
Enterprise 6,000 requests per minute

Exceeding the limits above will result in an HTTP 429 response. For information on rate limit headers, see Rate limits.

Batch geocoding is only available with an Enterprise plan. On all other plan levels, one geocode is permitted per request.

The results from geocoding with the mapbox.places mode must be displayed on a Mapbox map and cannot be stored permanently. The mapbox.places-permanent mode, available with an Enterprise plan, does not have these licensing restrictions.

The Mapbox Geocoding API coverage map lists the types of geocoding results support in each area of the world.

Request format

URL Parameter Description
query a location; a place name for forward geocoding or a coordinate pair (longitude, latitude location) for reverse geocoding
mode mapbox.places or mapbox.places-permanent for enterprise/batch geocoding (see Response format below)
Query Parameter Description
country
(optional)
ISO 3166 alpha 2 country codes, separated by commas
proximity
(optional)
Location around which to bias results, given as longitude,latitude
types
(optional)
Filter results by one or more type. Options are country , region , postcode , place , locality , neighborhood , address , poi . Multiple options can be comma-separated.
autocomplete
(optional)
Whether or not to return autocomplete results. Options are true and false . The default is true .

The {country} parameter limits results to a set of one or more countries, specified with ISO 3166 alpha 2 country codes and separated by commas.

The {proximity} parameter biases search results around a specific location given in {longitude},{latitude} coordinates. Results will not be filtered by location or ordered by distance, but location will be considered along with textual relevance and other criteria when scoring and sorting results.

The {autocomplete} parameter controls whether autocomplete results are included. Autocomplete results can partially match the query: for example, searching for washingto could include washington even though only the prefix matches. Autocomplete is useful for offering fast type-ahead or autocomplete results in user interfaces. If your queries represent complete addresses or place names, you can disable this behavior and exclude partial matches by setting the {autocomplete} parameter to false.

GET
/geocoding/v5/{mode}/{query}.json

Response format

Our geocoding data is updated and improved constantly and responses for a given query may change. Geocoding results are returned in Carmen GeoJSON format. This format declares the types and existence of properties, but not their specific values: their values can change as our data improves.

Feature IDs are formatted like {type}.{id}. {type} is one of the types listed above. Additional feature types may be added in the future, but the current types will stay the same. The numeric part of a feature ID may change between data updates.

The {properties} property of the feature is unstable: only what is specified in Carmen GeoJSON is part of the stable API.

Results are returned in order of relevance. They also have a relevance property that is based on how much of the query matched text in the result. You can use the relevance property to remove rough results if you require a response that matches your whole query.

Example response

{
  "type": "FeatureCollection",
  "query": [
    "los",
    "angeles"
  ],
  "features": [
    {
      "id": "place.33004",
      "type": "Feature",
      "text": "Los Angeles",
      "place_name": "Los Angeles, California, United States",
      "relevance": 0.99,
      "properties": {
        "wikidata": "Q65"
      },
      "bbox": [
        -118.521455009776,
        33.90189299,
        -118.12130699003,
        34.1614390095055
      ],
      "center": [
        -118.2439,
        34.0544
      ],
      "geometry": {
        "type": "Point",
        "coordinates": [
          -118.2439,
          34.0544
        ]
      },
      "context": [
        {
          "id": "postcode.8055854450707500",
          "text": "90012"
        },
        {
          "id": "region.6020809690311220",
          "text": "California",
          "wikidata": "Q99"
        },
        {
          "id": "country.12862386939497690",
          "text": "United States",
          "short_code": "us",
          "wikidata": "Q30"
        }
      ]
    },
    {
      "id": "place.15100",
      "type": "Feature",
      "text": "Los Ángeles",
      "place_name": "Los Ángeles, Bío Bío, Chile",
      "relevance": 0.99,
      "properties": {},
      "bbox": [
        -72.6835636,
        -37.6587686,
        -72.0420575,
        -37.1736364
      ],
      "center": [
        -72.3277,
        -37.4079
      ],
      "geometry": {
        "type": "Point",
        "coordinates": [
          -72.3277,
          -37.4079
        ]
      },
      "context": [
        {
          "id": "region.7807420235045040",
          "text": "Bío Bío",
          "wikidata": "Q2170"
        },
        {
          "id": "country.14661701841731110",
          "text": "Chile",
          "short_code": "cl",
          "wikidata": "Q298"
        }
      ]
    }
  ],
  "attribution": "NOTICE: © 2016 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained."
}

Search for places

Try this in API Playground

This is often called forward geocoding. Request feature data that best matches the input {query} text. The response includes one or more results ordered by relevance.

This API is used by the Mapbox.js L.mapbox.geocoderControl and the mapbox-gl-geocoder user interfaces.

GET
/geocoding/v5/{mode}/{query}.json

Example request

curl https://api.mapbox.com/geocoding/v5/mapbox.places/1600+pennsylvania+ave+nw.json

# using the proximity option to limit
# results to Canada. even though 1600 pennsylvania
# ave nw will usually return the white house
# in America, this will only return
# addresses in Canada
curl https://api.mapbox.com/geocoding/v5/mapbox.places/1600+pennsylvania+ave+nw.json?country=ca

# there are many towns named 'Chester', but adding a
# proximity parameter in New Jersey ensures that the town
# of Chester, New Jersey is in the search results
curl https://api.mapbox.com/geocoding/v5/mapbox.places/chester.json?proximity=-74.70850,40.78375

# search only for countries named Georgia,
# so that we don't find the state in America
curl https://api.mapbox.com/geocoding/v5/mapbox.places/georgia.json?types=country

Retrieve places near a location

Try this in API Playground

This is often called reverse geocoding. Request feature data located at the input {longitude},{latitude} coordinates. The response includes at most one result from each type.

URL Parameter Description
mode mapbox.places or mapbox.places-permanent for enterprise/batch geocoding (see Response format below)
Query Parameter Description
types
(optional)
Filter results by one or more type. Options are country , region , postcode , place , locality , neighborhood , address , poi . Multiple options can be comma-separated
GET
/geocoding/v5/{mode}/{longitude},{latitude}.json

Example request

curl https://api.mapbox.com/geocoding/v5/mapbox.places/-73.989,40.733.json

# filtering to only points of interest
curl https://api.mapbox.com/geocoding/v5/mapbox.places/-73.989,40.733.json?types=poi

Batch requests

This feature is only available with the mapbox.places-permanent mode

Batch requests have the same parameters as normal requests, but can include more than one query by separating queries with the ; character. Each query should be URL encoded, but the ; character should not be encoded: it should be included verbatim.

With the mapbox.places-permanent mode, you can do up to 50 forward or reverse geocoding queries in a single request. The response is an array of individual geocoder responses formatted the same as individual results. Each query in a batch request counts individually against your account's rate limits.

curl https://api.mapbox.com/geocoding/v5/mapbox.places-permanent/20001;20009;22209.json

Datasets

This API is in limited beta. Please request access if you would like to be part of the beta.

A dataset is an editable collection of GeoJSON features. The Datasets API offers persistent storage for custom geographic data and supports reading, creating, updating, and removing features either individually or in bulk.

Using the Datasets API involves interacting with two types of resources: datasets and features. Datasets contain a collection of features.

The dataset object

A dataset contains information about the dataset. Each dataset contains the following properties:

Property Description
owner the username of the dataset owner
id id for an existing dataset
created date and time the dataset was created
modified date and time the dataset was last modified
name
(optional)
the name of the dataset
description
(optional)
the description of the dataset

The dataset object

{
  "owner": "{username}",
  "id": "{dataset_id}",
  "created": "{timestamp}",
  "modified": "{timestamp}",
  "name": "{name}",
  "description": "{description}"
}

The feature object

A feature is a GeoJSON? Feature object representing a feature in the dataset.

For a full list of GeoJSON Feature properties, see the GeoJSON specification.

Limits

  • Each feature must be less than 500kB
  • A batch request cannot manipulate more than 100 features
  • The body of a batch request cannot excced 5MB

The feature object

{
  "id": "{feature_id}",
  "type": "Feature",
  "properties": {
    "prop0": "value0"
  },
  "geometry": {
    "coordinates": [ 102,0.5 ],
    "type": "Point"
  }
}

List datasets

Lists all datasets for a particular account.

GET
/datasets/v1/{username}
datasets:read Token scope

Example request

$ curl https://api.mapbox.com/datasets/v1/{username}

Example response

[
  {
    "owner": "{username}",
    "id": "{dataset_id}",
    "created": "{timestamp}",
    "modified": "{timestamp}"
  },
  {
    "owner": "{username}",
    "id": "{dataset_id}",
    "created": "{timestamp}",
    "modified": "{timestamp}"
  }
]

Create dataset

Creates a new, empty dataset.

POST
/datasets/v1/{username}
datasets:write Token scope

Example request

curl -X POST https://api.mapbox.com/datasets/v1/{username}

Example request body

{
  "name": "foo",
  "description": "bar"
}

Example response

{
  "owner": "{username}",
  "id": "{dataset_id}",
  "name": null,
  "description": null,
  "created": "{timestamp}",
  "modified": "{timestamp}"
}

Retrieve a dataset

Returns a single dataset.

Retrieve information about an existing dataset.

GET
/datasets/v1/{username}/{dataset_id}
datasets:read Token scope

Example request

curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}

Example response

{
  "owner": "{username}",
  "id": "{dataset_id}",
  "created": "{timestamp}",
  "modified": "{timestamp}"
}

Update a dataset

Updates the properties of a particular dataset.

PATCH
/datasets/v1/{username}/{dataset_id}
datasets:write Token scope

Example request

curl --request PATCH https://api.mapbox.com/datasets/v1/{username}/{dataset_id} \
  -d @data.json

Example request body

{
  "name": "foo",
  "description": "bar"
}

Example response

{
  "owner": "{username}",
  "id": "{dataset_id}",
  "name": "foo",
  "description": "bar",
  "created": "{timestamp}",
  "modified": "{timestamp}"
}

Delete a dataset

Deletes a dataset, including all features it contains.

DELETE
/datasets/v1/{username}/{dataset_id}
datasets:write Token scope

Example request

curl -X DELETE https://api.mapbox.com/datasets/v1/{username}/{dataset_id}

Example response

HTTP 204

List features

List features in a dataset. The response body will be a GeoJSON? FeatureCollection.

This endpoint supports pagination so that you can list many features.

GET
/datasets/v1/{username}/{dataset_id}/features
datasets:read Token scope

Example request

curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features

# using pagination to only list 10 features
curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features?limit=10

# using pagination to start the listing after feature with the id f6d9
curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features?start=f6d9

Example response

{
  "type": "FeatureCollection",
  "features": [
    {
      "id": "{feature_id}",
      "type": "Feature",
      "properties": {
        "prop0": "value0"
      },
      "geometry": {
        "coordinates": [ 102,0.5 ],
        "type": "Point"
      }
    },
    {
      "id": "{feature_id}",
      "type": "Feature",
      "properties": {
        "prop0": "value0"
      },
      "geometry": {
        "coordinates": [
          [ 102, 0 ],
          [ 103, 1 ],
          [ 104, 0 ],
          [ 105, 1 ]
        ],
        "type": "LineString"
      }
    }
  ]
}

Insert or update a feature

Inserts or updates a feature in a dataset. If there's already a feature with the given ID in the dataset, it will be replaced. If there isn't a feature with that ID, a new feature is created.

Property Description
id the id of an existing feature in the dataset
PUT
/datasets/v1/{username}/{dataset_id}/features/{feature_id}
datasets:write Token scope

Example request

curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/{feature_id} \
  -X PUT \
  -d @file.geojson

Example request body

{
  "id": "{feature_id}",
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [ 100, 0 ],
        [ 101, 0 ],
        [ 101, 1 ],
        [ 100, 1 ],
        [ 100, 0 ]
      ]
    ]
  },
  "properties": {
    "prop0": "value0"
  }
}

Example response

{
  "id": "{feature_id}",
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [ 100, 0 ],
        [ 101, 0 ],
        [ 101, 1 ],
        [ 100, 1 ],
        [ 100, 0 ]
      ]
    ]
  },
  "properties": {
    "prop0": "value0"
  }
}

Retrieve a feature

Retrieves a feature in a dataset.

GET
/datasets/v1/{username}/{dataset_id}/features/{feature_id}
datasets:read Token scope

Example request

curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/{feature_id}

Example response

{
  "id": "{feature_id}",
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [ 100, 0 ],
        [ 101, 0 ],
        [ 101, 1 ],
        [ 100, 1 ],
        [ 100, 0 ]
      ]
    ]
  },
  "properties": {
    "prop0": "value0"
  }
}

Delete a feature

Removes a feature from a dataset.

DELETE
https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/{feature_id}
datasets:write Token scope

Example request

curl -X DELETE https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features/{feature_id}

Example response

HTTP 204

Batch-update a set of features

Modifies a dataset by creating, updating, and deleting features in a batch. Up to 100 features may be provided in one request.

Property Description
put an array of features to add to the dataset
delete an array of feature IDs to delete from the dataset
POST
https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features
datasets:write Token scope

Example request

curl https://api.mapbox.com/datasets/v1/{username}/{dataset_id}/features \
  -X POST \
  -d @updates.json

Example request body

{
  "put": [
    {
      "id": "{feature_id}",
      "type": "Feature",
      "properties": {
        "prop0": "value0"
      },
      "geometry": {
        "coordinates": [ 102, 0.5 ],
        "type": "Point"
      }
    },
    {
      "id": "{feature_id}",
      "type": "Feature",
      "properties": {
        "prop0": "value0"
      },
      "geometry": {
        "coordinates": [
          [ 102, 0 ],
          [ 103, 1 ],
          [ 104, 0 ],
          [ 105, 1 ]
        ],
        "type": "LineString"
      }
    }
  ],
  "delete": [
    "{feature_id}",
    "{feature_id}"
  ]
}

Example response

{
  "put": [
    {
      "id": "{feature_id}",
      "type": "Feature",
      "properties": {
        "prop0": "value0"
      },
      "geometry": {
        "coordinates": [ 102, 0.5 ],
        "type": "Point"
      }
    },
    {
      "id": "{feature_id}",
      "type": "Feature",
      "properties": {
        "prop0": "value0"
      },
      "geometry": {
        "coordinates": [
          [ 102, 0 ],
          [ 103, 1 ],
          [ 104, 0 ],
          [ 105, 1 ]
        ],
        "type": "LineString"
      }
    }
  ],
  "delete": [
    "{feature_id}",
    "{feature_id}"
  ]
}

Distance

The Mapbox Distance API returns all travel times between many points.

For example, given 3 locations A, B, C, the Distance API will return a matrix of travel times in seconds between each location:

A B C
A A → A A → B A → C
B B → A B → B B → C
C C → A C → B C → C

This API allows you to build tools that efficiently check the reachability of coordinates from each other, filter points by travel time, or run algorithms for solving optimization problems.

Limits

  • Maximum 100 coordinate pairs per request
  • Maximum 60 requests per minute

For higher volumes, contact us.

Retrieve a duration matrix

Returns a duration matrix showing travel times between given locations.

The {profile} parameter of your request should be a Mapbox Directions routing profile? ID. The following IDs are supported:

  • driving for car travel times
  • walking for pedestrian and hiking travel times
  • cycling for bicycle travel times

The Content-Type header of the request needs to be set to application/json.

Property Description
coordinates an array of up to 100 [longitude, latitude] coordinate pairs

The Distance API returns an object that resembles a matrix, or table, of durations: the time it takes to get between two points on the shortest route in seconds. The order of durations in the response object is directly related to the order of coordinates in the request body.

The Distance API will always return the duration on the fastest route. Durations between points may not be symmetric, as the routes may differ by direction (for example, A to B may have a different duration than B to A). The Distance API only returns durations in seconds; it does not return route geometries.

The duration between the same coordinate is always 0. If a duration can not be found, the result is null. All values are in seconds.

Property Description
durations an array of arrays of durations in seconds
POST
/distances/v1/mapbox/{profile}

Example Request

curl -X POST \
  --header "Content-Type:application/json" \
  -d @coordinates.json \
  "https://api.mapbox.com/distances/v1/mapbox/driving"

Example request body

{
  "coordinates": [
    ["A"],
    ["B"],
    ["C"]
  ]
}
{
  "coordinates": [
    [13.41894, 52.50055],
    [14.10293, 52.50055],
    [13.50116, 53.10293]
  ]
}

Example response

{
  "durations": [
    ["A to A", "A to B", "A to C"],
    ["B to A", "B to B", "B to C"],
    ["C to A", "C to B", "C to C"]
  ]
}
{
  "durations": [
    [0,    2910, null],
    [2903, 0,    5839],
    [4695, 5745, 0   ]
  ]
}

Analytics

This API is available for premium and enterprise plans.

The Mapbox Analytics API returns API usage for services by resource. For example, it can calculate the number of geocoding requests made in a week with a specific access token?.

Retrieve analytics

Returns the request counts per day for given resource and period.

  • If the {resourceType} is tokens, the {id} is the complete token.
  • If the {resourceType} is styles, the {id} is the Style ID. Not to be confused with the Style URL, the id is the alphanumeric segment at the end of the style: the Style URL mapbox://styles/user/cimdoca6f00 contains the Style ID cimdoca6f00, so the analytics request would have the path /analytics/v1/styles/user/cimdoca6f00.
  • If the {resourceType} is tilesets, the {id} is a Map ID.
URL Parameter Description
resourceType The resource being requested. Valid resource types are accounts , tokens , tilesets or styles .
username The username for the account that owns the resource.
id
(optional)
The id for the resource. In the case of accounts this isn't required.
period
(optional)
2 comma separated dates as ISO formatted strings . The first date must be earlier than the second. The period is inclusive of dates provided. Defaults to last 90 days if not provided. The maximum period is 1 year. If the provided dates are more than 1 year apart, an error will be returned.

Responses include arrays of request counts per service.

Property Description
timestamps an array of dates as ISO formatted strings for each day included in the response.
period a 2 element array with start and end dates as ISO formatted strings for the response period.
services an object with a key per service the value of which is an array of request counts per day in the same sequence as timestamps .

Only services applicable to the given resource are returned in the response.

Resource type Services returned in response
accounts mapview static tile directions geocode
tokens mapview static tile directions geocode
tilesets mapview static tile
styles mapview static tile

For the styles resource type, Static & Tile services refer to the Static API. For tilesets, Static & Tile services refer to the Static (Classic) and Maps → Tiles APIs.

GET
/analytics/v1/{resourceType}/{username}/{id}?period={period}
analytics:read Token scope

Example Request

curl https://api.mapbox.com/analytics/v1/tilesets/mapbox/mapbox.streets?period=2016-03-22T00:00:00.000Z,2016-03-24T00:00:00.000Z

Example response

{
    "period": ["2016-03-22T00:00:00.000Z", "2016-03-24T00:00:00.000Z"],
    "timestamps": ["2016-03-22T00:00:00.000Z", "2016-03-23T00:00:00.000Z", "2016-03-24T00:00:00.000Z"],
    "services": {
        "mapview": [ 25, 22, 37 ],
        "static": [ 23, 20, 34 ],
        "tiles": [ 30, 39, 53 ]
    }
}
Show examples in:
Mapbox API Documentation