I am using the Google Place Autocomplete API to search for cities in India. I used the following code to filter the Autocomplete:
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);
}
});
On running this code, the autocomplete dialog shows a Can't load search results error message.
The same code works fine when I set the country as .setCountry("UK")
. What am I doing wrong? Is there an alternate method for restricting the autocomplete?
从.setCountry("India")
更改为.setCountry("IN")
写国家代码而不是国家名称...更多信息在这里
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.