Skip to main content

Address Autofill

Public beta for Mapbox Search JS

Mapbox Search JS is in public beta. During the public beta phase, frameworks may be subject to potential changes as they stabilize.

AddressAutofillCore

A AddressAutofillCore object is an application's main entrypoint to the Mapbox Address Autofill API. The Mapbox Address Autofill API is an API similar to SearchBoxCore, but targeted towards address autocomplete.

Only address types are returned by the API.

AddressAutofillCore is focused on the two-step, interactive search experience. These steps are:

  1. AddressAutofillCore#suggest: The user enters a search term, and a list of suggested results is returned with address data.
  2. AddressAutofillCore#retrieve: The user selects a result from the list of suggested results, and the corresponding geographic coordinates are returned.

A Mapbox access token is required to use AddressAutofillCore, and other options may be specified either in the constructor or in the AddressAutofillCore#suggest call.

new AddressAutofillCore(options: AddressAutofillOptions?)

Parameters

options(AddressAutofillOptions?)
NameDescription
options.accessToken
string?

Instance Members

Methods

Was this section on AddressAutofillCore helpful?

AddressAutofillOptions

Options used by AddressAutofillCore and useAddressAutofillCore to control the location, language, country, and limit of results. All properties are optional.

Object

Properties

bbox((string | LatLngBoundsLike)): Limit results to only those contained within the supplied bounding box.
country(string): An ISO 3166 alpha-2 country code to be returned. If not specified, results will not be filtered by country.
language(string): The IETF language tag to be returned. If not specified, en will be used.
limit((string | number)): The number of results to return, up to 10 .
proximity((string | LngLatLike)): Bias the response to favor results that are closer to this location. Provide a point coordinate provided as a LngLatLike , or use the string ip to use the requester's IP address.
streets((string | boolean)): If enabled, street results may be returned in addition to addresses. Defaults to true .
Was this section on AddressAutofillOptions helpful?

AddressAutofillSuggestion

An AddressAutofillSuggestion object represents a suggestion result from the Mapbox Address Autofill API.

Suggestion objects are "part one" of the two-step interactive autofill experience. Suggestion objects do not include geographic coordinates.

To get the coordinates of the result, use AddressAutofillCore#retrieve.

For tracking purposes, it is useful for any follow-up requests based on this suggestion to include same SessionToken as the original request.

Example

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

const sessionToken = new SessionToken();
const result = await search.autofill('Washington D.C.', { sessionToken });
if (result.suggestions.length === 0) return;

const suggestion = result.suggestions[0];
const { features } = await autofill.retrieve(suggestion, { sessionToken });
doSomethingWithCoordinates(features);

Instance Members

Was this section on AddressAutofillSuggestion helpful?

AddressAutofillFeatureSuggestion

An AddressAutofillFeatureSuggestion object represents GeoJSON suggestion results from the Mapbox Address Autofill API.

As per the Mapbox Address Autofill API, this will always be Point.

any

Example

const featureSuggestion = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [0,0]
},
properties: {
feature_name: 'Washington D.C.',
}
};

Static Members

Was this section on AddressAutofillFeatureSuggestion helpful?
Was this section on AddressAutofillSuggestionResponse helpful?
Was this section on AddressAutofillRetrieveResponse helpful?

MatchCode

An object describing the level of confidence that the given response feature matches the address intended by the request query.

Instance Members

Was this section on MatchCode helpful?

MatchCodeType

An indication of how well a context component of the feature matches the query.

Static Members

Was this section on MatchCodeType helpful?

MatchCodeConfidence

An overall confidence level for how well the feature matches the query.

Static Members

Was this section on MatchCodeConfidence helpful?
Was this page helpful?