问题描述
我的目标是将来自 Google Places Android API 的自动完成结果限制为仅限特定国家/地区(美国).
My goal is to restrict the Autocomplete results from the Google Places Android API to a particular country (United States) only.
我正在使用以下 API:
I am using the following API:
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
看起来 LatLngBounds 应该可以完成这项工作.
Looks like LatLngBounds is supposed to do this job.
如果是,那么美国的 LatLngBounds 值是多少?
If yes, then what are the values of LatLngBounds for United States?
您使用哪个来源获取某个国家/地区的 LatLngBounds?
Which source did you use to get LatLngBounds for a country?
LatLngBounds 是一个矩形 - 因此它也可以在结果中包含其他国家/地区.那个怎么样?
LatLngBounds is a rectange - so it can include other countries in the result as well. What about that?
有更好的方法吗?
推荐答案
从 Google Play Services v9.6 开始,您现在可以为自动完成建议设置国家/地区过滤器.请确保您的 Play 服务版本至少为 v9.6
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);
您可以使用他们的ISOAplha 2"代码
这篇关于在 Google Places Android API 中将自动完成搜索限制为特定国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!