My app have to provide a Place Autocompleter for Google APIs. But there should only display locations for selected countries. For example only addresses in US and in UK. Here the used code-snipped for the filter:
AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_COUNTRY)
.setCountry("US")
.build();
Is there any solution to set the method setCountry() to multiple counties? I have tried .setCountrie("US, UK") ... but this don't work.
any idea?
AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_COUNTRY)
.setCountry("my|country:ph|country:sg")
.build();
This works for me. iOS SDK set like this. That's how I know.
A new method setCountries()
has been added to the SDK.
implementation 'com.google.android.libraries.places:places:2.2.0'
Java
Intent intent = new Autocomplete.IntentBuilder(
AutocompleteActivityMode.OVERLAY, fields)
.setCountries(Arrays.asList("FR", "IT"))
.build(this);
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
Kotlin
val intent = Autocomplete.IntentBuilder(
AutocompleteActivityMode.OVERLAY, fields)
.setCountries(listOf("FR", "IT"))
.build(this)
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE)
Note: keep in mind autocomplete results to up to five countries according to the documentation
this an old question: but for those who are still not able to get the .setCountries(Arrays.asList("DZ", "US")) and only getting the .setCountry("US") make sure to update your place api in the gradle as 12/26/2020 its version 2.4.0
implementation 'com.google.android.libraries.places:places:2.4.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With