smeijer / leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
https://smeijer.github.io/leaflet-geosearch/
MIT License
1.03k stars 273 forks source link

Limit autocomplete results to a geographic frame #246

Closed yurixcode closed 3 years ago

yurixcode commented 3 years ago

Hi! first of all congratulate you for the work done in your bookstore, thank you!

I would like to know if it is possible to limit the results of the geo search to a previously defined geographic frame

For example, if the search limitation is located in Madrid, that the provider returns only results that are included within this geographic area, would it be possible to do this with this library?

I already appreciate your response.

Cheers

smeijer commented 3 years ago

Hi,

Yes, that's possible, but how it exactly works, and to what scope you can limit, depends on the provider that you use.

Please check the provider specific docs, and let me know if you are not able to make it work.

For the OpenStreetMap provider, you can take a look at the example here: https://smeijer.github.io/leaflet-geosearch/providers/openstreetmap#optional-parameters

All providers that we support, have a link on their page to the official docs. And all providers can proxy those official options right to their API. Just like the openstreetmap example shows.

cargallo commented 3 years ago

Hi, I'm trying to use optional parameters but it doesn't working.

Here is the code I'm using const provider = new OpenStreetMapProvider() as the provider:

image

and here are the results:

image

cargallo commented 3 years ago

Ok, I just realize of my error. The provider must be initialized like below, and not at query instance:

const provider = new OpenStreetMapProvider({
  params: {
    countrycodes: 'ar', // limit search results to Argentina
    addressdetails: 1, // include additional address detail parts
  },
});
smeijer commented 3 years ago

Correct @cargallo . Thanks for coming back to let us know :slightly_smiling_face: