【发布时间】:2016-11-23 14:18:54
【问题描述】:
我正在使用适用于 Android 的 Places.GeoDataApi,根据执行请求的设备的位置,我会得到不同的搜索结果。我需要结果始终位于边界内。我看不到可以在 getAutocompletePredictions 请求中设置的位置。我有什么遗漏吗?
我通过以下方式使用 GoogleApiClient 和 Places API 获得地址/地点自动填充建议:
Places.GeoDataApi.getAutocompletePredictions()
该方法需要一个 GoogleApiClient 对象、一个用于自动完成的 String 以及一个用于限制搜索范围的 LatLngBounds 对象。这就是我的用法:
LatLngBounds bounds = new LatLngBounds(new LatLng(38.46572222050097, -107.75668023304138),new LatLng(39.913037779499035, -105.88929176695862));
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.build();
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(googleApiClient, "Starbucks", bounds, null);
正在使用的版本:com.google.android.gms:play-services-location:8.3.0
文档: https://developers.google.com/places/android/autocomplete
【问题讨论】:
标签: google-maps google-places-api google-places android-googleapiclient