【发布时间】:2019-02-20 09:36:26
【问题描述】:
我正在研究谷歌地图和搜索。
在地图上搜索的唯一选项是 Google Places API。 https://developers.google.com/places/android-sdk/intro
其中还指出您播放服务版本的 SDK 已弃用。
所以我试图用新的 SDK 来实现它。 现在我想要的是而不是自动完成来打开一个新的活动,我希望它在我的自动完成中显示为一个列表。
但问题是它适用于 Play 服务版本,但不适用于 Compat 版本,因为类和导入不同。
这是我遇到问题的代码部分:
// Submit the query to the autocomplete API and retrieve a PendingResult that will
// contain the results when the query completes.
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
// This method should have been called off the main UI thread. Block and wait for at most 60s
// for a result from the API.
AutocompletePredictionBuffer autocompletePredictions = results
.await(60, TimeUnit.SECONDS);
// Confirm that the query completed successfully, otherwise return null
final Status status = autocompletePredictions.getStatus();
if (!status.isSuccess()) {
Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
Toast.LENGTH_SHORT).show();
Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
autocompletePredictions.release();
return null;
}
如果有人使用 New Places API 库实现 PlacesAutoCompleteAdapter。请指导我更改上述代码。
谢谢。
【问题讨论】:
标签: android google-play-services google-places-api googleplacesautocomplete