【问题标题】:Restrict Autocomplete search to "India" in Google Places API在 Google Places API 中将自动完成搜索限制为“印度”
【发布时间】:2018-02-27 17:39:12
【问题描述】:

我正在使用 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") 时,相同的代码可以正常工作。我究竟做错了什么?是否有限制自动完成的替代方法?

【问题讨论】:

    标签: java android google-api google-places-api


    【解决方案1】:

    .setCountry("India")更改为.setCountry("IN")写国家代码而不是国家名称...更多信息here

    【讨论】:

    猜你喜欢
    • 2016-01-25
    • 2013-10-11
    • 1970-01-01
    • 2017-11-22
    • 2020-07-07
    • 2020-06-10
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多