在Google Places Android API中限制自动填充搜索到特定国家/地区 [英] Restrict Autocomplete search to a particular country in Google Places Android API

查看:279
本文介绍了在Google Places Android API中限制自动填充搜索到特定国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是仅将Google Places Android API的自动填充结果限制到特定国家/地区(美国)。



我使用以下API:

  PendingResult< AutocompletePredictionBuffer> results = 
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient,constraint.toString(),
mBounds,mPlaceFilter);

看起来LatLngBounds应该可以完成这项工作。


  1. 如果是,那么美国LatLngBounds的值是多少?


  2. 您使用哪种来源获取LatLngBounds的国家?

  3. LatLngBounds是一个rectange - 因此它可以在结果中包含其他国家/地区。那个怎么样?

  4. 有没有更好的方法来做到这一点? 从Google Play服务v9.6开始,您现在可以设置您的自动填充建议的国家/地区过滤器。请确保您的Play服务版本至少为v9.6

      AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
    .setTypeFilter(Place.TYPE_COUNTRY)
    .setCountry(US)
    .build();
    Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
    .setFilter(autocompleteFilter)
    .build(this);

    您可以使用他们的 ISO'Aplha 2'Codes


    My goal is to restrict the Autocomplete results from the Google Places Android API to a particular country (United States) only.

    I am using the following API:

            PendingResult<AutocompletePredictionBuffer> results =
                    Places.GeoDataApi
                            .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                    mBounds, mPlaceFilter);
    

    Looks like LatLngBounds is supposed to do this job.

    1. If yes, then what are the values of LatLngBounds for United States?

    2. Which source did you use to get LatLngBounds for a country?

    3. LatLngBounds is a rectange - so it can include other countries in the result as well. What about that?

    4. Is there a better way to do it?

    解决方案

    Starting from Google Play Services v9.6,you can now set a country filter to your autocomplete suggestions. Please make sure your Play Services version is at least v9.6

    AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
                                .setTypeFilter(Place.TYPE_COUNTRY)
                                .setCountry("US")
                                .build();
    Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                                        .setFilter(autocompleteFilter)
                                        .build(this);  
    

    You can change the country codes by using their ISO 'Aplha 2' Codes

    这篇关于在Google Places Android API中限制自动填充搜索到特定国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆