" language="jsx" data-testid="live-editor" style="position:relative;text-align:left;box-sizing:border-box;padding:0;overflow:hidden;white-space:pre;font-family:Inconsolata;color:#393A34;background-color:#f6f8fa">
import { OpenStreetMapProvider } from 'leaflet-geosearch';const provider = new OpenStreetMapProvider();// add to leafletimport { GeoSearchControl } from 'leaflet-geosearch';map.addControl(new GeoSearchControl({provider,style: 'bar',}),);
Note that OpenStreetMap is open, but not free without limits. They do have a Usage Policy just like the other providers. Provide the email
property to opt-in for authenticated requests.
const provider = new OpenStreetMapProvider({params: {email: 'john@example.com', // auth for large number of requests},});
OpenStreetMap Nominatim supports a number of optional parameters. As the api requires those parameters to be added to the url, they can be added to the params
key of the provider.
All options defined next to the params
key, would have been added to the request body.
const provider = new OpenStreetMapProvider({params: {'accept-language': 'nl', // render results in Dutchcountrycodes: 'nl', // limit search results to the Netherlandsaddressdetails: 1, // include additional address detail parts},});