Android Google Places API,getAutocompletePredictions返回状态为"PLACES_API_ACCESS_NOT_CONFIGURED" [英] Android Google Places API, getAutocompletePredictions returns status 'PLACES_API_ACCESS_NOT_CONFIGURED'

查看:97
本文介绍了Android Google Places API,getAutocompletePredictions返回状态为"PLACES_API_ACCESS_NOT_CONFIGURED"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Android Google Places API时遇到问题-自动完成功能. 我使用了与Android Google Maps API相同的密钥(在文档中这样写就可以了).这是清单中我的定义:

I'm having problems with Android Google Places API - auto complete feature. I use the same key that i used for Android Google Maps API (and in the documentation, it is written this is ok). Here is my definition in manifest:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="mykey"/>

但是getAutocompletePredictions返回"PLACES_API_ACCESS_NOT_CONFIGURED"消息作为状态.

But getAutocompletePredictions returns 'PLACES_API_ACCESS_NOT_CONFIGURED' message as status.

这是我的Java代码:

Here is my Java code:

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,并在凭据页面上检查您的密钥仍然存在

Enable the Google Places API for Android in developers console and check on the credentials page that your key is still present

这篇关于Android Google Places API,getAutocompletePredictions返回状态为"PLACES_API_ACCESS_NOT_CONFIGURED"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆