我正在使用Google Place Autocomplete API搜索印度的城市。我使用以下代码过滤自动完成:
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
.setCountry("India")
.build();
autocompleteFragment.setFilter(typeFilter);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i("TAG", "Place: " + place.getName());
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i("TAG", "An error occurred: " + status);
}
});
运行此代码时,自动填充对话框会显示Can't load search results错误消息。
将国家/地区设置为.setCountry("UK")
时,相同的代码可以正常工作。我究竟做错了什么?是否有另一种限制自动完成的方法?