Is there a way to add get sorted data from leaflet-geosearch?

26 views Asked by At

Right now the results I am getting are not sorted by the closest location, I am using the OpenStreetMapProvider. The closest suggestion to user's current location should appear on the top and farthest one should be at the bottom

I tried searching for params to make this happen but have not found anything, morever haven't been able to make any event hanlder work in this regard either, the idea was to sort them manually before they appear on the screen.

Suggestions on any of these are welcome or anything that works:

  • Ability to give a param to the provider so that the result can be sorted
  • a way to get access to the results so that I can sort them myself before they appear in the search.

**MapsSearch.jsx**

`export default function MapsSearch(props) { const map = useMap();

useEffect(() => {
    const searchControl = new SearchControl({
        provider: props.provider,
        ...props,
        style: "bar",
    });

    map.addControl(searchControl);
    return () => map.removeControl(searchControl);
    // eslint-disable-next-line react-hooks/exhaustive-deps
}, [props]);

return null;

}`

Its called like this: <MapsSearch provider={searchProvider} showMarker={false} showPopup={false} popupFormat={({ query, result }) => result.label} maxMarkers={3} retainZoomLevel={false} animateZoom={true} autoClose={true} searchLabel={"Enter your address"} keepResult={true} >

0

There are 0 answers