gpt4 book ai didi

android - 如何调用 setCountry() 到 AutocompleteFilter Google place API?

转载 作者:太空宇宙 更新时间:2023-11-03 11:55:06 24 4
gpt4 key购买 nike

我正在实现 PlaceAutocompleteFragment 以自动完成位置。我想将我的搜索限制在特定国家(就像之前我们在 url 中使用 component=UK)。我怎样才能在下面的代码中实现这一点。

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_REGIONS)
.build();
autocompleteFragment.setFilter(typeFilter);

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.i(TAG, "Place: " + place.getName());
Log.i(TAG, "Place: " + place.getId());
}

@Override
public void onError(Status status) {
Log.i(TAG, "Place: " + status);
}
});

请帮忙..

最佳答案

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_COUNTRY).setCountry("UK")
.build();
autocompleteFragment.setFilter(typeFilter);

您需要确保播放版本应该是编译 'com.google.android.gms:play-services:9.6.1'

关于android - 如何调用 setCountry() 到 AutocompleteFilter Google place API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com