" 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();const results = await provider.search({ query: input.value });
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.
import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';const searchControl = new GeoSearchControl({provider: new OpenStreetMapProvider(),style: 'bar',resetButton: '🔍', // Example of using a magnifying glass icon});map.addControl(searchControl);
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:
interface result {x: number; // lony: number; // latlabel: string; // formatted addressbounds: [[number, number], // south, west - lat, lon[number, number], // north, east - lat, lon];raw: any; // raw provider result}