This content has moved to developers.arcgis.com. Please update your bookmarks!
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
Constructor | Description |
---|---|
L.esri.Geocoding.geocode(<Object> |
Creates a new Geocode task |
You can pass any options you can pass to L.esri.Task. The url
will be the ArcGIS World Geocoder by default but a custom geocoding service can also be used.
Methods
Method | Returns | Description |
---|---|---|
text(<String> |
this |
The text to geocode. If you specify text other params like address , city , subregion , region , postal , and country will be ignored.
|
address(<String> |
this |
The street and house number to be geocoded. |
neighborhood(<String> |
this |
The neighborhood to be geocoded. |
city(<String> |
this |
The city to be geocoded. |
subregion(<String> |
this |
The subregion to be geocoded. |
region(<String> |
this |
The region to be geocoded. |
postal(<String> |
this |
The postal code to be geocoded. |
country(<String> |
this |
The country to be geocoded. |
category(<String> |
this |
The optional category to search for. A list of valid categories can be found here. |
within(<L.LatLngBounds> |
this |
A bounding box used to filter results. |
nearby(<L.LatLng> |
this |
Increase the match score of candidates close to a location passed within the request. |
run(<Function> |
|
Executes the request chain and accepts the response callback. |
Examples
<link rel="stylesheet" href="./esri-leaflet-geocoder.css">
<script src="./esri-leaflet-geocoder.js"></script>
L.esri.Geocoding.geocode({apikey: 'YOUR API KEY'}).text('380 New York St, Redlands, California, 92373').run(function (err, results, response) {
if (err) {
console.log(err);
return;
}
console.log(results);
});
L.esri.Geocoding.geocode({apikey: 'YOUR API KEY'}).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);
});
// 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 API KEY'}).text('Denver').within(bounds).run(function (err, response) {
if (err) {
console.log(err);
return;
}
console.log(response);
});
// Using .nearby()
var denver = L.latLng(37.712, -108.227);
L.esri.Geocoding.geocode({apikey: 'YOUR API KEY'}).text('Highlands Ranch').nearby(denver, 20000).run(function (err, response) {
if (err) {
console.log(err);
return;
}
console.log(response);
});
Results Object
In the examples 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.)
}
}
]
}