This is the geocoder control. It works like any other Leaflet control, and is added to the map.
var map = L.map('map').setView([0, 0], 2);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.Control.geocoder().addTo(map);
Factory | Description |
---|---|
L.Control.geocoder( |
Instantiates a new geocoder control, by default using Nominatim for search, unless anothergeocoder is specified in the options. |
Option | Type | Default | Description |
---|---|---|---|
showResultIcon |
Boolean
| false |
Enable icons describing result type, if available |
collapsed |
Boolean
| true |
Search field is collapsed (minimized) by default |
expand |
String
| "click" |
Method used for expanding the control; should be "click" or "hover" |
position |
String
| "topright" |
Sets the control's position, see Leaflet's Control docs |
placeholder |
String
| "Search..." |
Search field's placeholder text |
errorMessage |
String
| "Nothing found." |
Message shown when an error occurs, or no results are found |
geocoder |
IGeocoder
| L.Routing.Geocoder.nominatim() |
Geocoder backend to use when searching |
Method | Returns | Description |
---|---|---|
markGeocode( |
|
Called when a geocoding result is selected by the user. Default implementation opens a marker on the result's location and opens a popup with the result's name. |
An interface implemented to respond to geocoding queries.
Method | Returns | Description |
---|---|---|
geocode( |
|
Performs a geocoding query (search). When the search completes, the callback is calledwith an array of IGeocodeResult s as argument |
reverse( |
|
Tries to find locations close to the coordinate latLng . When the search completes,the callback is called
with an array of IGeocodeResult s as argument. |
suggest( |
|
Tries to find suggestions given a (possibly incomplete) search query. When the search completes, the callback is called
with an array of IGeocodeResult s as argument. This method is optional to implement. |
An object that represents a result from a geocoding query.
Note that there is not concrete implementation of IGeocodeResult
, it
is the contract (interface) geocoders are expected to use when returning
results.
Property | Type | Description |
---|---|---|
name
| ||
bounds
| ||
center
| ||
icon?
| ||
html?
|
Geocoder using OpenStreetMap's Nominatim service.
Option | Type | Default | Description |
---|---|---|---|
serviceUrl |
String
| '//nominatim.openstreetmap.org/' |
URL used to locate the Nominatim service |
geocodingQueryParams |
Object
| {} |
Parameters added to each geocoding request |
reverseQueryParams |
Object
| {} |
Parameters added to each reverse geocoding request |
htmlTemplate |
Function
|
|
Function used to generate the HTML representation of a geocoding response; the function will be passed a parsed Nominatim geocoding response and should return a String |