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

后端 未结 5 1732
野的像风
野的像风 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:20

    If you are using PlaceAutocompleteFragment you can set it like this:

    AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
                            .setTypeFilter(Place.TYPE_COUNTRY)
                            .setCountry("US")
                            .build();
    
    mAutocompleteFragment.setFilter(autocompleteFilter);
    

提交回复
热议问题