Geocoding

This page includes reference documentation for the Geocoding feature in the Mapbox Search JS Core framework.

Class

GeocodingCore

A GeocodingCore object is an application's main entrypoint to the Mapbox Geocoding API. The Geocoding API allows forward (location to coordinates) and reverse (coordinates to location) queries, enabled by corresponding methods from the GeocodingCore object.

A Mapbox access token is required to use GeocodingCore, and other options may be specified either in the constructor or in the GeocodingCore#forward or GeocodingCore#reverse calls.

new GeocodingCore(options: <a href="/mapbox-search-js/api/core/geocoding/#geocodingoptions">GeocodingOptions</a>?)

Parameters

NameDescription
options GeocodingOptions? 
options.accessToken string? 

Example

const geocode = new GeocodingCore({ accessToken: 'pk.my-mapbox-access-token' });

const results = await geocode.forward('Washington D.C.');
if (results.features.length === 0) return;

const feature = results.features[0];
doSomethingWithCoordinates(feature);

Instance Members

The Mapbox access token to use for all requests.

Type
string

Any default options (GeocodingOptions) to be merged into options in the following methods:

Type
Partial<GeocodingOptions>

Programmatic search

GeocodingCore#forward allows you to look up a feature by name and returns the feature(s) and corresponding geographic coordinates in GeoJSON format.

Legal terms:

Due to legal terms from our data sources, geographic coordinates should be used ephemerally and not persisted. If the results are to be cached/stored in a customer database, calls to GeocodingCore#forward should specify permanent: true within the method options argument.

This permanent policy is consistent with the Mapbox Terms of Service and failure to comply may result in modified or discontinued service.

Additionally, the Mapbox Terms of Service states any rendering of a feature suggestion must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).

Disclaimer:

The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.

Parameters
NameDescription
searchText String 
optionsArg GeocodingOptions? 
optionsArg.signal AbortSignal? 
Returns
Promise<GeocodingResponse>
Example
const results = await geocode.forward('Washington D.C.');
if (results.features.length === 0) return;

const feature = results.features[0];
doSomethingWithCoordinates(feature);

GeocodingCore#reverse allows you to look up a single pair of coordinates and returns the geographic feature or features that exist at that location in GeoJSON format.

Legal terms:

Due to legal terms from our data sources, geographic coordinates should be used ephemerally and not persisted. If the results are to be cached/stored in a customer database, calls to GeocodingCore#reverse should specify permanent: true within the method options argument.

This permanent policy is consistent with the Mapbox Terms of Service and failure to comply may result in modified or discontinued service.

Additionally, the Mapbox Terms of Service states any rendering of a feature suggestion must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).

Disclaimer:

The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.

Parameters
NameDescription
lngLat (String | LngLatLike) 
optionsArg GeocodingOptions? 
optionsArg.signal AbortSignal? 
Returns
Promise<GeocodingResponse>
Example
const results = await geocode.reverse({ lat: 40.7736, lng: -73.9749 });
if (results.features.length === 0) return;

const feature = results.features[0];
doSomethingWithFeature(feature);

Interactive search

GeocodingCore#suggest is a managed endpoint for an interactive SearchSession, such as one operated through a web or React component. It accepts a search text string for either a GeocodingCore#forward or GeocodingCore#reverse geocoding query and returns a GeocodingResponse object.

Parameters
NameDescription
searchText String 
optionsArg GeocodingOptions? 
optionsArg.signal AbortSignal? 
Returns
Promise<GeocodingResponse>
Example
const result = await geocode.suggest('123 Main St');
if (results.features.length === 0) return;

const feature = results.features[0];
doSomethingWithCoordinates(feature);

GeocodingCore#retrieve is a managed endpoint for an interactive SearchSession, such as one operated through a web or React component. It accepts a GeocodingFeature object and returns the same object. It is used in a SearchSession to respond to a user's selection of a feature suggestion. Unlike the Search Box API, the Geocoding API returns all feature data in the initial response, so this method does not perform any further data retrieval.

Parameters
NameDescription
suggestion GeocodingFeature 
Returns
Promise<GeocodingFeature>
このsection on GeocodingCoreは役に立ちましたか?YesNo

Options and Type Definitions

GeocodingOptions

Options object for configuring GeocodingCore, mapped to Geocoding API parameters.

Type

Object

Properties

NameDescription
autocomplete boolean When autocomplete is enabled, results will be included that start with the requested string, rather than just responses that match it exactly.

Defaults to true.

bbox (string | LngLatBoundsLike) Limit results to only those contained within the supplied bounding box.
country string Limit results to one or more countries. Permitted values are ISO 3166 alpha 2 country codes separated by commas.
language string An IETF language tag that controls the language of the text supplied in responses, and also affects result scoring.
limit number The number of results to return, up to 10 .

Defaults to 5.

permanent boolean Permanent geocodes are used for use cases that require storing data indefinitely. If 'true', requests will be made with permanent enabled. Separate billing for permanent geocoding will apply.

If undefined or 'false', the geocoder will default to use temporary geocoding. Temporary geocoding results are not allowed to be cached.

For questions related to permanent resource usage and billing, contact Mapbox sales.

proximity (string | LngLatLike) Bias the response to favor results that are closer to this location.

Provided as two comma-separated coordinates in longitude,latitude order, or the string ip to bias based on reverse IP lookup.

types (string | Set<FeatureTypes>) Filter results to include only a subset (one or more) of the available feature types. Multiple options can be comma-separated.
worldview string Available worldviews are: cn , in , jp , us . If a worldview is not set, us worldview boundaries will be returned.
このsection on GeocodingOptionsは役に立ちましたか?YesNo

GeocodingResponse

A GeocodingResponse object represents a returned data object from the Mapbox Geocoding API.

Type

Object

Properties

NameDescription
attribution string Attributes the results of the Mapbox Geocoding API to Mapbox.
features Array<GeocodingFeature> The returned feature objects.
type "FeatureCollection" "FeatureCollection" , a GeoJSON type from the GeoJSON specification .
このsection on GeocodingResponseは役に立ちましたか?YesNo

GeocodingFeature

A GeocodingFeature object represents a GeoJSON feature result from the Mapbox Geocoding API.

Legal terms:

Due to legal terms from our data sources, results from the Mapbox Geocoding API should use the permanent=true flag if the results are to be cached/stored in a customer database. Otherwise, results should be used ephemerally and not persisted.

This permanent policy is consistent with the Mapbox Terms of Service and failure to comply may result in modified or discontinued service.

Additionally, the Mapbox Terms of Service states any rendering of a feature suggestion must be using Mapbox map services (for example, displaying results on Google Maps or MapKit JS is not allowed).

Disclaimer:

The failure of Mapbox to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.

Type

any

Static Members

Feature id. This property is named "id" to conform to the GeoJSON specification, but is the same id referred to as mapbox_id within the properties object.

Type
string

Related

このsection on GeocodingFeatureは役に立ちましたか?YesNo

GeocodingFeatureProperties

Raw GeoJSON feature properties from the Mapbox Geocoding API.

Reference: https://docs.mapbox.com/api/search/geocoding-v6/#geocoding-response-object

Type

Object

Properties

NameDescription
bbox LngLatBoundsLike A bounding box for the feature. This may be significantly larger than the geometry. This property is only provided with features of type country , region , postcode , district , place , locality , or neighborhood .
context Partial<GeocodingFeatureContext> Object representing the hierarchy of encompassing parent features.
coordinates Coordinates Coordinate and accuracy data for a geographic feature.
feature_type string A string describing the geographic type of the feature. See FeatureTypes for supported options.
full_address string The full feature text string, combining name_preferred and place_formatted .
mapbox_id string Feature id. The mapbox_id uniquely identifies a feature in the Mapbox search database. Mapbox ID’s are accepted in requests to the Geocoding API as a forward search, and will return the feature corresponding to that id.
match_code MatchCode Match codes for each context component of an address, plus an overall match confidence. Provides an indication of how well each part of the address matched the query.
name string Formatted string of the most granular geographical component of the feature. For example, for an address this will be the address number and street. For features known by multiple aliases, this field will represent the alias, if one is available, matching the queried text.
name_preferred string Similar to name , except this will always be the canonical or otherwise more common alias for the feature name. For example, searching for "America" will return "America" as the name , and "United States" as name_preferred.
place_formatted string Formatted string of the feature context (e.g. place + region + country + postcode + counry ). The part of the full feature name which comes after name .
このsection on GeocodingFeaturePropertiesは役に立ちましたか?YesNo

GeocodingFeatureContext

Object representing the hierarchy of encompassing parent features for a given GeocodingFeature.

Type

{address: GeocodingFeatureContextComponent, street: GeocodingFeatureContextComponent, neighborhood: GeocodingFeatureContextComponent, postcode: GeocodingFeatureContextComponent, locality: GeocodingFeatureContextComponent, place: GeocodingFeatureContextComponent, district: GeocodingFeatureContextComponent, region: GeocodingFeatureContextComponent, country: GeocodingFeatureContextComponent}

Properties

NameDescription
address GeocodingFeatureContextComponent 
country GeocodingFeatureContextComponent 
district GeocodingFeatureContextComponent 
locality GeocodingFeatureContextComponent 
neighborhood GeocodingFeatureContextComponent 
place GeocodingFeatureContextComponent 
postcode GeocodingFeatureContextComponent 
region GeocodingFeatureContextComponent 
street GeocodingFeatureContextComponent 

Static Members

Address context component. Includes separate address_number and street_name properties.

Type
GeocodingFeatureContextComponent

Street context component.

Type
GeocodingFeatureContextComponent

Neighborhood context component.

Type
GeocodingFeatureContextComponent

Postcode context component.

Type
GeocodingFeatureContextComponent

Locality context component.

Type
GeocodingFeatureContextComponent

Place context component.

Type
GeocodingFeatureContextComponent

District context component.

Type
GeocodingFeatureContextComponent

Region context component. If available, may include additional region_code and region_code_full properties.

Type
GeocodingFeatureContextComponent

Country context component. Includes additional country_code and country_code_alpha_3 properties.

Type
GeocodingFeatureContextComponent
Related
このsection on GeocodingFeatureContextは役に立ちましたか?YesNo

GeocodingFeatureContextComponent

Object representing one level of hierarcy among encompassing parent features for a given GeocodingFeature.

Type

Object

Properties

NameDescription
mapbox_id string The unique Mapbox ID of the context feature.
name string A string representing the feature in the requested language, if specified.
wikidata_id string The Wikidata identifier for the returned feature.
このsection on GeocodingFeatureContextComponentは役に立ちましたか?YesNo

FeatureTypes

Geographic feature data types for the Mapbox Geocoding API.

Type

("country" | "region" | "postcode" | "district" | "place" | "locality" | "neighborhood" | "street" | "block" | "address" | "secondary_address")

Related

このsection on FeatureTypesは役に立ちましたか?YesNo

Coordinates

Coordinate and accuracy data for a geographic feature.

Type

Object

Properties

NameDescription
accuracy string A coordinate accuracy indicator for address features. Can be one of rooftop , parcel , point , interpolated , approximate .
latitude number The latitude of the feature.
longitude number The longitude of the feature.
routable_points Array<RoutablePoint> Routable point data for an address feature.
このsection on Coordinatesは役に立ちましたか?YesNo

RoutablePoint

Routable point data for an address feature.

Type

Object

Properties

NameDescription
latitude number The latitude of the routable point.
longitude number The longitude of the routable point.
name string The name of the routable point.
このsection on RoutablePointは役に立ちましたか?YesNo