K.K*_*K.K 21 android google-api google-places-api
我的目标是将Google Places Android API的自动填充结果限制为仅限特定国家/地区(美国).
我使用以下API:
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
Run Code Online (Sandbox Code Playgroud)
看起来像LatLngBounds应该做这个工作.
如果是,那么美国的LatLngBounds值是多少?
您使用哪个来源为一个国家/地区获取LatLngBounds?
LatLngBounds是一个矩形 - 因此它也可以在结果中包含其他国家/地区.那个怎么样?
有没有更好的方法呢?
Yan*_*kee 22
从Google Play Services 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);
Run Code Online (Sandbox Code Playgroud)
您可以使用ISO'Aplha 2'代码更改国家/地区代码
Mal*_*azi 11
如果您使用的是PlaceAutocompleteFragment,可以像这样设置:
AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_COUNTRY)
.setCountry("US")
.build();
mAutocompleteFragment.setFilter(autocompleteFilter);
Run Code Online (Sandbox Code Playgroud)
LatLngBounds构造函数方法定义如下所示:
LatLngBounds (LatLng southwest, LatLng northeast)
Run Code Online (Sandbox Code Playgroud)
即它取两个LatLng值一个用于边界的西南位置,另一个是边界的东北位置,并且矩形的另外两个点是平凡计算的.
If yes, then what are the values of LatLngBounds for United States?
Run Code Online (Sandbox Code Playgroud)
我的粗略猜测,如果我没有错,西南LatLng值将是32.6393,-117.004304 ,东北LatLng值将是44.901184,美国为-67.32254.
Which source did you use to get LatLngBounds for a country?
Run Code Online (Sandbox Code Playgroud)
我通常使用http://www.findlatitudeandlongitude.com/通过将标记放在所需位置来检查这些LatLng值.
LatLngBounds is a rectange - so it can include other countries in the result as well. What about that?
Run Code Online (Sandbox Code Playgroud)
是的,你是正确的,上面的边界将是纯矩形,并且不可能使用这些边界将结果限制为仅美国.
这是因为矩形[bounds]将使用我们提供给构造函数的两个Latlng点[SE&NW]来计算,并且其他两个点将被平凡地计算.
Is there a better way to do it?
Run Code Online (Sandbox Code Playgroud)
是的,您可以使用Google Places Web Service API .Below教程解释了如何使用API ..
http://codetheory.in/google-place-api-autocomplete-service-in-android-application/
您可以使用地址类型和地址组件以您希望的方式使用此API限制结果:https: //developers.google.com/maps/documentation/geocoding/intro#Types
您可以使用链接中提到的类型按国家/地区,区域和其他各种类型进行限制.
希望能帮助到你!!
PS:如果有人可以回答如何限制在Play Services API中使用Bounds到特定国家,这将是非常好的!
| 归档时间: |
|
| 查看次数: |
16614 次 |
| 最近记录: |