--- layout: api title: "v1.6.4 JavaScript Library: L.mapbox.geocoder(id|url)" categories: api version: v1.6.4 permalink: /api/v1.6.4/l-mapbox-geocoder ---

## L.mapbox.geocoder(id|url)

A low-level interface to geocoding, useful for more complex uses and reverse-geocoding.

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

id or url

string

Value must be

- An `id` string `examples.map-foo`
- A URL to TileJSON, like `{{site.tileApi}}/v3/examples.map-0l53fhk2.json`

Returns a `L.mapbox.geocoder` object.

### geocoder.query(queryString, callback)

Queries the geocoder with a query string, and returns its result, if any.

Options | Value | Description
--- | --- | ---
queryString (required) | string | a query, expressed as a string, like 'Arkansas'
callback (required) | function | a callback

The callback is called with arguments

1. An error, if any

2. The result. This is an object with the following members:

        {
            results: // raw results
            latlng: // a map-friendly latlng array
            bounds: // geojson-style bounds of the first result
            lbounds: // leaflet-style bounds of the first result
        }

Example: Live example of geocoder.query centering a map.

Returns: the geocoder object. The return value of this function is not useful - you must use a callback to get results.

### geocoder.reverseQuery(location, callback)

Queries the geocoder with a location, and returns its result, if any.

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

location (required)

object

A query, expressed as an object:

-     [lon, lat] // an array of lon, lat

-     { lat: 0, lon: 0 } // a lon, lat object

-     { lat: 0, lng: 0 } // a lng, lat object

The first argument can also be an array of objects in that form to geocode more than one item.

callback (required)

function

The callback is called with arguments

- An error, if any
- The result. This is an object of the raw result from Mapbox.

Returns: the geocoder object. The return value of this function is not useful - you must use a callback to get results.