![](/img/trans.png)
[英]Restrict Autocomplete search to a particular country in Google Places Android API
[英]How to Use google places api in android with restrict particular place?
嗨,我基本上我想創建一個具有Autocomplete TextView並根據用戶搜索顯示位置的應用程序,我只是限制用戶僅顯示印度的城市名稱,而不能顯示其他城市。 有人知道嗎?
要搜索僅限於印度的地點,您可以在代碼中使用setBoundsBias() 。Google現在提供了自動填充小部件,這使事情變得更加簡單。 請查看此鏈接: https : //developers.google.com/places/android-api/autocomplete
創建一個過濾器,並在過濾器中將setCountry設置為India,然后在PlaceAutoComplete片段或intent中設置該過濾器。
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setCountry("IN")
.build();
autocompleteFragment.setFilter(typeFilter);
這對我有用
try {
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
.setCountry("au")
.build();
Intent intent = new PlaceAutocomplete.IntentBuilder
(PlaceAutocomplete.MODE_FULLSCREEN)
.setFilter(typeFilter)
.build(ProfileActivity.this);
startActivityForResult(intent, REQUEST_SELECT_PLACE);
} catch (GooglePlayServicesRepairableException |
GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.