Geocoding
Geocoding provides a UI search component for forward and reverse geocoding, allowing users to search for addresses and control a Mapbox GL JS map.
This page includes reference documentation for the MapboxGeocoder class, part of the Mapbox Search JS Web framework.
For installation instructions and a helpful introduction to using Address Confirmation in your website or app, see our Web Geocoding Quickstart Guide.
Class
MapboxGeocoder
MapboxGeocoder is a class that lets you search for addresses and places using
the Mapbox Geocoding API.
Instantiating it produces a DOM element you can append anywhere in your document.
You can also pass it to a Mapbox GL JS map
via map.addControl() to zoom to selected results; MapboxGeocoder implements the
IControl interface.
To use this class, you must have a Mapbox access token.
Example
// Example using a Mapbox GL JS Map
const map = new mapboxgl.Map({
accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
container: 'map',
center: [-99.1332, 19.4326],
zoom: 9
});
const geocoder = new MapboxGeocoder();
geocoder.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
map.addControl(geocoder);
// Example using as a standalone geocoder
const geocoder = new MapboxGeocoder();
geocoder.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
geocoder.options = {
language: 'es',
country: 'MX',
proximity: [-99.1332, 19.4326]
}
// append to the DOM - (adjust as necessary for your document)
document.querySelector('div').appendChild(geocoder);
Instance Members
Map settings
Methods
Map binding
Events
Options and Type Definitions
MapboxGeocoderComponentOptions
Options to configure component-specific Search behavior
ObjectProperties
| Name | Description |
|---|---|
customSearchfunction (text: string): Promise<Array<GeocodingFeature>> | A function accepting the query string which performs supplemental search results on top of those from the Mapbox Geocoding API. Expected to return a Promise which resolves to an array of GeoJSON-like Features as described in the Mapbox Geocoding API . |
| If true, the coordinates in the query string are expected to be (lat,lng) instead of (lng,lat). | |
If
false
, animating the map to a selected result is disabled. If
true
(default), animating the map will use the default animation parameters. If an object, it will be passed as
options
to the map
flyTo
method.
|