Pelias Provider
Pelias is an open-source geocoder powered completely by open data, available freely to everyone.
In order to use this provider you'll need to have your own Pelias server running.
The Docker repository provides the quickest path to running your own server.
See the Pelias documentation for more detailed information about the available endpoints and query parameters.
Looking for a hosted version of Pelias? check out the Geocode Earth provider.
import { PeliasProvider } from 'leaflet-geosearch';// Pelias servers are self-hosted so you'll need to configure the 'options.host' string// to identify where requests to your running pelias/api server instance should be sent.// note: you SHOULD include the scheme, domain and port but NOT any path or parameters.const provider = new PeliasProvider({ host: 'http://localhost:4000' });// add to leafletimport { GeoSearchControl } from 'leaflet-geosearch';map.addControl(new GeoSearchControl({provider,style: 'bar',}),);
Optional parameters
Pelias supports a wide range of number of optional parameters which can be applied to every request using the params
object:
const provider = new PeliasProvider({params: {size: 5, // limit the total number of results returnedlang: 'nl', // render results in Dutch'boundary.country': 'NL', // limit search results to the Netherlandslayers: 'address,street', // limmit which layers are queried},});
Or individually on a per-request basis:
const results = await provider.search({query: {text: 'example','focus.point.lat': 1.11, // score results nearer to the focus point higher'focus.point.lon': 2.22,},});