Address Autofill
This page includes reference documentation for the Address Autofill feature in the Mapbox Search JS Core framework.
Class
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:
- AddressAutofillCore#suggest: The user enters a search term, and a list of suggested results is returned with address data.
- 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.
Parameters
Name | Description |
---|---|
Instance Members
Methods
Options and Type Definitions
AddressAutofillOptions
Options used by AddressAutofillCore and useAddressAutofillCore to control the location, language, country, and limit of results. All properties are optional.
Object
Properties
Name | Description |
---|---|
bbox((string | LngLatBoundsLike)) | Limit results to only those contained within the supplied bounding box. |
An ISO 3166 alpha-2 country code to be returned. If not specified, results will not be filtered by country. | |
The
IETF language tag
to be returned. If not specified,
en
will be used.
| |
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.
|
If enabled, street results may be returned in addition to addresses. Defaults to
true
.
|
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.
Object
Properties
Name | Description |
---|---|
A point accuracy metric for the returned address feature. Can be one of
rooftop
,
parcel
,
point
,
interpolated
,
intersection
,
street
.
| |
Action block of the suggestion result. contains id to execute retrieve | |
Address level 1 from the WHATWG Autocomplete Specification | |
Address level 2 from the WHATWG Autocomplete Specification | |
Address level 3 from the WHATWG Autocomplete Specification | |
Address line 1 from the WHATWG Autocomplete Specification | |
Address line 2 from the WHATWG Autocomplete Specification | |
Address line 3 from the WHATWG Autocomplete Specification | |
An array of context objects representing the hierarchy of encompassing parent features for a given feature. | |
Long form country name, for example: "United States" | |
The short form country name, for example: "us". This follows the ISO 3166 alpha-2 country code specification. | |
Additional details, such as city and state for addresses. | |
The name of the feature. | |
The full address of the suggestion. | |
The IETF language tag of the feature. | |
The name of the Maki icon associated with the feature. | |
Feature id. The
mapbox_id
uniquely identifies a feature in the Mapbox search database.
| |
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. | |
The feature name, as matched by the search algorithm. | |
Address metadata fields of the feature.
Includes the short form country name, for example: "us". This follows the ISO 3166 alpha-2 country code specification. | |
A string representing the feature in the requested language, if specified, and its full result hierarchy. | |
An array of strings representing the geographic feature type of the feature. Possible values include "address" and "secondary_address". | |
Postal code. |
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);
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
AddressAutofillFeatureContextComponent
Object representing one level of hierarcy among encompassing parent features for a given AddressAutofillSuggestion.
Object
Properties
Name | Description |
---|---|
An identifier prefixed with the component type, for example
country.123
.
| |
The unique Mapbox ID of the context feature. | |
A string representing the feature in the requested language, if specified. | |
The Wikidata identifier for the returned feature. |
AddressAutofillSuggestionResponse
Response object returned when calling the suggest
method of AddressAutofillCore
Object
Properties
Name | Description |
---|---|
The attribution data for results. | |
The returned suggestion objects. |
AddressAutofillRetrieveResponse
Response object returned when calling the retrieve
method of AddressAutofillCore
Object
Properties
Name | Description |
---|---|
The attribution data for results. | |
The returned feature objects. |
MatchCode
An object describing the level of confidence that the given response feature matches the address intended by the request query.
Object
Properties
Name | Description |
---|---|
An indication of how well the
address_number
component of the feature matches the query.
| |
An overall confidence level for how well the feature matches the query. | |
An indication of how well the
country
component of the feature matches the query.
| |
An indication of how well the
locality
component of the feature matches the query.
| |
An indication of how well the
place
component of the feature matches the query.
| |
An indication of how well the
postcode
component of the feature matches the query.
| |
An indication of how well the
region
component of the feature matches the query.
| |
An indication of how well the
secondary_address
component of the feature matches the query.
| |
An indication of how well the
street
component of the feature matches the query.
|
MatchCodeType
An indication of how well a context component of the feature matches the query.
Static Members
MatchCodeConfidence
An overall confidence level for how well the feature matches the query.