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

How to provide parameters other than address in search query. #159

Closed vishalvisd closed 4 years ago

vishalvisd commented 6 years ago

As per the code in providers/googleProvider, the query value just assumes to be address parameter. What if we want to provide other parameters which google api supports. In my case, I want to send 'component' parameter like components=country:AU.

Ref: googleProvider.js line number 42 (library version: 2.6.0)

Or if there is some other way this is already possible please point that out.

smeijer commented 4 years ago

Sorry for the late response. I hope the answer might be useful for future googlers:

All providers are simple proxies to their endpoints. In case of google, all optional parameters can be added to the params key in the way google would expect to have them in the URL.

I've updated the docs with an example

For the component parameter, that would become something like:

const provider = new GoogleProvider({
  params: {
    key: '__YOUR_GOOGLE_KEY__',
    components: 'country:AU',
  },
});

See the Google Docs for more info about the parameters that can be added to the params key.