--- layout: api title: "v1.6.4 JavaScript Library: L.mapbox.geocoderControl(id|url, options)" categories: api version: v1.6.4 permalink: /api/v1.6.4/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.

This function is currently in private beta: Contact Mapbox before using this functionality.

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

id or url (required)

string

Either a

- An `id` string `examples.map-foo`
- A URL to TileJSON, like `{{site.tileApi}}/v3/examples.map-0l53fhk2.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.

Example:

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

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

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

event

string

- `found`: success in finding a location. Called with a single argument, the result.
- `error`: failure to find a location. Called with the raw HTTP error from Mapbox.

event

string

- `select`: fired when the user selects a location from a list of options returned from a geocoding request. The geocoding data is attached to the `data` property of the event.

event

string

- `autoselect`: fired when the geocoder control automatically chooses the first result of a query that returns only one result, and repositions the map accordingly. The geocoding data is attached to the `data` property of the event.