Skip to content

L.esri.Geocoding.Geocode

Extends L.esri.Task

L.esri.Geocoding.Geocode is an abstraction for submitting geocoding requests. You can find more information and the source code for this plugin here.

Constructor

ConstructorDescription
L.esri.Geocoding.geocode(<Object> options)Creates a new Geocode task

You can pass any options you can pass to L.esri.Task. The url will be the ArcGIS geocoding service by default but a custom geocoding service can also be used.

Methods

MethodReturnsDescription
text(<String> text)thisThe text to geocode. If you specify text, other params like address, city, subregion, region, postal, and country will be ignored.
address(<String> text)thisThe street and house number to be geocoded.
neighborhood(<String> text)thisThe neighborhood to be geocoded.
city(<String> text)thisThe city to be geocoded.
subregion(<String> text)thisThe subregion to be geocoded.
region(<String> text)thisThe region to be geocoded.
postal(<String> text)thisThe postal code to be geocoded.
country(<String> text)thisThe country to be geocoded.
category(<String> category)thisThe optional category to search for. A list of valid categories can be found here.
within(<L.LatLngBounds> bounds)thisA bounding box used to filter results.
nearby(<L.LatLng> latlng, <Integer> distance)thisIncrease the match score of candidates close to a location passed within the request.
run(<Function> callback, <Object> context)XMLHttpRequestExecutes the request chain and accepts the response callback.

Examples

Geocode a string

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
L.esri.Geocoding.geocode({apikey: 'YOUR_ACCESS_TOKEN'}).text('380 New York St, Redlands, California, 92373').run(function (err, results, response) {
    if (err) {
    console.log(err);
    return;
    }
    console.log(results);
});

Geocode an address

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
L.esri.Geocoding.geocode({apikey: 'YOUR_ACCESS_TOKEN'}).address('380 New York St').city('Redlands').region('California').postal(92373).run(function (err, results, response) {
    if (err) {
    console.log(err);
    return;
    }
    console.log(results);
});

Geocode within an extent

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
// Using .within()
var southWest = L.latLng(37.712, -108.227);
var northEast = L.latLng(41.774, -102.125);
var bounds = L.latLngBounds(southWest, northEast); // Colorado

L.esri.Geocoding.geocode({apikey: 'YOUR_ACCESS_TOKEN'}).text('Denver').within(bounds).run(function (err, response) {
    if (err) {
    console.log(err);
    return;
    }
    console.log(response);
});

Geocode a nearby address

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
// Using .nearby()
var denver = L.latLng(37.712, -108.227);

L.esri.Geocoding.geocode({apikey: 'YOUR_ACCESS_TOKEN'}).text('Highlands Ranch').nearby(denver, 20000).run(function (err, response) {
    if (err) {
    console.log(err);
    return;
    }
    console.log(response);
});

Result

In the samples above the results object will look like this:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
{
    results: [
        {
            latlng: L.LatLng,
            text: 'Formatted Address',
            score: 100, // certainty ranking of the match
            properties: {
            // additional info like specific address components (Country Code etc.)
            }
        }
    ]
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.