Autofill
Mapbox Search JS is in public beta. During the public beta phase, frameworks may be subject to potential changes as they stabilize.
MapboxAutofill
A MapboxAutofill
object is an application's main entrypoint to the
Mapbox Autofill API. The Mapbox Autofill API is an API similar to MapboxSearch,
but targeted towards address autocomplete.
Only address types are returned by the API.
MapboxAutofill
is focused on the two-step, interactive search experience. These steps are:
- MapboxAutofill#suggest: The user enters a search term, and a list of suggested results is returned with address data.
- MapboxAutofill#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 MapboxAutofill
, and
other options may be specified either in the constructor or in the MapboxAutofill#suggest call.
Parameters
Instance Members
Methods
AutofillSuggestion
An AutofillSuggestion
object represents a suggestion
result from the Mapbox 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 MapboxAutofill#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 MapboxAutofill({ 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
AutofillFeatureSuggestion
An AutofillFeatureSuggestion
object represents GeoJSON
suggestion results from the Mapbox Autofill API.
As per the Mapbox Autofill API, this will always be Point.
anyExample
const featureSuggestion = {type: 'Feature',geometry: {type: 'Point',coordinates: [0,0]},properties: {feature_name: 'Washington D.C.',}};
Static Members
MatchCode
An object describing the level of confidence that the given response feature matches the address intended by the request query. Includes boolean flags denoting matches for each address sub-component.