Usage
There are two ways in which leaflet-geosearch can be used. Direct usage, for example for address forms, or embedded in a leaflet map to search for points of interest.
Using the providers directly
All providers can be used without leaflet. You might want to bind them to a form;
Reverse geocoding
reverse returns the places at a position, closest first, in the same format as search:
OpenStreetMap, LocationIQ, CivilDefenseMap, Photon, Pelias, Geocode Earth, Geoapify, GeoApiFr and PdokNl support it. The other providers reject with "This provider does not support reverse geocoding".
leaflet-geosearch imports Leaflet, which only runs in a browser. For server-side rendering (Next.js, Nuxt, ...), import the providers from leaflet-geosearch/providers. It has the same providers and doesn't import Leaflet:
Using the leaflet control
Or add the GeoSearchControl to the leaflet map instance, to render a search control on your map;
See Leaflet Control for more info about the the options this control provides.
Leaflet 2
The control works with Leaflet 1.6 and up, and with Leaflet 2. Leaflet 2 has no factory functions like L.map() and no global L in its ES modules, so create the map with new Map() and import what you need by name. The control is used the same way:
Without a bundler, load Leaflet 2's leaflet-global.js, which sets window.L, before the UMD build of leaflet-geosearch:
Leaflet 2 is only published as ES modules. The CommonJS build of leaflet-geosearch loads it with require('leaflet'), which works in Node 20.19+ and 22.12+.
Results
The search event of all providers return an array of result objects. The base structure is uniform between the providers. It contains objects matching the following interface: