我正在实现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);
您需要确保play版本应编译为“com.google.android.gms:play services:9.6.1”