--- layout: api title: "v2.0.0 JavaScript Library: L.mapbox.geocoderControl(id|url, options)" categories: api version: v2.0.0 permalink: /api/v2.0.0/l-mapbox-geocodercontrol ---

## L.mapbox.geocoderControl(id|url, options)

Adds geocoder functionality as well as a UI element to a map. This uses the Mapbox Geocoding API.

Options | Value | Description
--- | --- | ---

id or url (required)

string

Either a

- An geocoder index ID, e.g. `mapbox.places-v1`
- A geocoder API URL, like `{{site.tileApi}}/v4/geocode/mapbox.places-v1/{query}.json`

options

object

An options argument with the same options as the `L.Control` class, as well as:

- `keepOpen`: a boolean for whether the control will stay open always rather than being toggled. Default `false`. See live example.
- `accessToken`: Mapbox API access token. Overrides `L.mapbox.accessToken` for this control.

Example:

    var map = L.map('map')
        .setView([37, -77], 5)
        .addControl(L.mapbox.geocoderControl('mapbox.places-v1'));

Returns a `L.mapbox.geocoderControl` object.

Class: `L.mapbox.GeocoderControl`

### geocoderControl.setURL(url)

Set the url used for geocoding.

Options | Value | Description
--- | --- | ---
url | string | A geocoding url

Returns: the geocoder control object

### geocoderControl.setID(id)

Set the map id used for geocoding.

Options | Value | Description
--- | --- | ---
id | string | A map id to geocode from

Returns: the geocoder control object

### geocoderControl.setTileJSON(tilejson)

Set the TileJSON used for geocoding.

Options | Value | Description
--- | --- | ---
tilejson | object | A TileJSON object

Returns: the geocoder object

### geocoderControl.on(event, callback)

Bind a listener to an event emitted by the geocoder control. Supported additional events are

Event | Description
--- | ---
found | Success in finding a location. The event's `results` property contains the raw results.
error | Failure to find a location. The event's `error` property contains the raw HTTP error.
select | Fired when the user selects a location from a list of options returned from a geocoding request. The event's `feature` property contains the selected GeoJSON Feature.
autoselect | Fired when the control automatically selects the first result of a query that returns only one result, and repositions the map accordingly. The event's `feature` property contains the selected GeoJSON feature.