actengage / vue-place-autocomplete

A Vue component for the Google Place Autocomplete API.
Other
26 stars 27 forks source link

Filter results by country? #6

Open ryanmwc opened 4 years ago

ryanmwc commented 4 years ago

I don't see anywhere in your docs on how to filter results by country. Do you not have this set up as a prop?

Braunmann commented 4 years ago

In vue-place-autocomplete/src/PlaceAutocompleteField.vue line 306 is:

        // can be used to restrict results to specific groups. Currently, you can use componentRestrictions to filter by up to 5 countries. Countries must be passed as as a two-character, ISO 3166-1 Alpha-2 compatible country code. Multiple countries must be passed as a list of country codes. z
        componentRestrictions: undefined,

Unfortunetly I do not know how to use this.

trasigor commented 4 years ago

This should works:

<place-autocomplete-field
          :api-key="**********"
          :component-restrictions='{country: ["us", "de"]}'
></place-autocomplete-field >
mattg1995 commented 4 years ago

This should works:

<place-autocomplete-field
          :api-key="**********"
          :component-restrictions='{country: ["us", "de"]}'
></place-autocomplete-field >

This doesn't seem to work for me at all, I can see the restrictions being applied to the component but it is still not filtering the results

Chup4Chups commented 4 years ago

Do you have any workaround to filter the results by country ? Also, is there any plan to get same feature to filter zipCode or City ?

NWBY commented 4 years ago

Anyone found a solution to this yet?

CSalih commented 3 years ago
:component-restrictions='{country: ["AT", "de", "ch", "it"]}'
:libraries="['geometry', 'places', '&language=at&region=AT']"

Doing this will not restrict to these country's. I add a region in libraries and the result will now prioritized to the country's within component-restrictions. Not the best solution but can used till this will fixed.

gbrits commented 3 years ago

🥳 Using the suggested solution by @CSalih worked great for me. I needed to restrict to addresses in Australia, with the following:

:component-restrictions='{country: ["AU"]}'
:libraries="['geometry', 'places', '&language=EN&region=AU']"