Skip to content
Software capabilities
Mapbox

How to forward-geocode an address with Mapbox

Use Mapbox Geocoding to turn an address or place name into coordinates. Use GeocodingCore in Mapbox Search JS when a browser application needs a typed SDK route.

Documentation reviewed · 2 methods with sources

Ways to do it

  1. API: GET /search/geocode/v6/forward
  2. SDK: Mapbox Search JS GeocodingCore
API

GET /search/geocode/v6/forward

Forward-geocode a URL-encoded address or place name.

Read source: Mapbox Geocoding API
Requirements
A valid Mapbox access token in access_token. The query must be at most 20 words and 256 characters.
Limitations
The default is 5 results and the maximum is 10. The default rate limit is 1,000 requests/minute and can vary by account. Use permanent geocoding when storing results.

Example shell

curl --fail --get 'https://api.mapbox.com/search/geocode/v6/forward' \
  --data-urlencode 'q=1600 Pennsylvania Avenue NW, Washington, DC' \
  --data-urlencode 'limit=5' \
  --data-urlencode "access_token=$MAPBOX_TOKEN"
SDK

Mapbox Search JS GeocodingCore

Use the Search JS GeocodingCore SDK to forward-geocode from a web application.

Read source: Mapbox Search JS GeocodingCore
Requirements
The @mapbox/search-js-core package and a Mapbox access token.
Limitations
GeocodingCore defaults to 5 results and accepts up to 10. Temporary results cannot be cached. Setting permanent: true uses separate billing.

Example text

import { GeocodingCore } from "@mapbox/search-js-core"

const geocoder = new GeocodingCore({ accessToken: MAPBOX_TOKEN })
const result = await geocoder.forward("1600 Pennsylvania Avenue NW, Washington, DC", { limit: 5 })