env*_*ver 26 android google-places-api
我遇到Android Google Places API问题 - 自动完成功能.我使用的是与Android Google Maps API相同的密钥(在文档中,写的是可以的).这是我在清单中的定义:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="mykey"/>
Run Code Online (Sandbox Code Playgroud)
但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();
Run Code Online (Sandbox Code Playgroud)
提前致谢
and*_*rei 51
在开发人员控制台中启用适用于Android的Google Places API,并检查您的密钥仍然存在的凭据页面
| 归档时间: |
|
| 查看次数: |
30384 次 |
| 最近记录: |