我在使用 Android Google Places API - 自动完成功能时遇到问题。
我使用与 Android Google Maps API 相同的密钥(在文档中,写的是这样可以)。这是我在清单中的定义:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="mykey"/>
但 getAutocompletePredictions 返回“PLACES_API_ACCESS_NOT_CONFIGURED”消息作为状态。
这是我的Java代码:
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
LatLngBounds latLngBounds = new LatLngBounds.Builder().
include(SphericalUtil.computeOffset(latlon, RADIUS, 0)).
include(SphericalUtil.computeOffset(latlon, RADIUS, 90)).
include(SphericalUtil.computeOffset(latlon, RADIUS, 180)).
include(SphericalUtil.computeOffset(latlon, RADIUS, 270)).build();
PendingResult<AutocompletePredictionBuffer> result = Places.GeoDataApi.getAutocompletePredictions(googleApiClient, constraint.toString(), latLngBounds, null);
AutocompletePredictionBuffer autocompletePredictions = result.await(Config.DATA_TIMEOUT, TimeUnit.MILLISECONDS);
Status status = autocompletePredictions.getStatus();
if (status.isSuccess()) {
Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
while (iterator.hasNext()) {
AutocompletePrediction prediction = iterator.next();
//... do stuff here ...
}
}
else {
Log.d(TAG, status.getStatusMessage());
}
autocompletePredictions.release();
googleApiClient.disconnect();
提前致谢
在开发者控制台中启用适用于 Android 的 Google Places API,并在凭据页面上检查您的密钥是否仍然存在
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)