Extends L.esri.
L.esri.
is an abstraction for submitting geocoding requests. You can find more information and the source code for this plugin here.
Constructor
Constructor | Description |
---|---|
L.esri. | 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
Method | Returns | Description |
---|---|---|
text( | this | The text to geocode. If you specify text , other params like address , city , subregion , region , postal , and country will be ignored. |
address( | this | The street and house number to be geocoded. |
neighborhood( | this | The neighborhood to be geocoded. |
city( | this | The city to be geocoded. |
subregion( | this | The subregion to be geocoded. |
region( | this | The region to be geocoded. |
postal( | this | The postal code to be geocoded. |
country( | this | The country to be geocoded. |
category( | this | The optional category to search for. A list of valid categories can be found here. |
within( | this | A bounding box used to filter results. |
nearby( | this | Increase the match score of candidates close to a location passed within the request. |
run( | XML | Executes the request chain and accepts the response callback. |
Examples
Geocode a string
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
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
// 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
// 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:
{
results: [
{
latlng: L.LatLng,
text: 'Formatted Address',
score: 100, // certainty ranking of the match
properties: {
// additional info like specific address components (Country Code etc.)
}
}
]
}