Restrict Autocomplete search to a particular country in Google Places Android API

后端 未结 5 1734
野的像风
野的像风 2020-12-15 17:44

My goal is to restrict the Autocomplete results from the Google Places Android API to a particular country (United States) only.

I am using the following API:

5条回答
  •  别那么骄傲
    2020-12-15 18:17

    Starting from Google Play Services v9.6,you can now set a country filter to your autocomplete suggestions. Please make sure your Play Services version is at least v9.6

    AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
                                .setTypeFilter(Place.TYPE_COUNTRY)
                                .setCountry("US")
                                .build();
    Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                                        .setFilter(autocompleteFilter)
                                        .build(this);  
    

    You can change the country codes by using their ISO 'Aplha 2' Codes

提交回复
热议问题