Android Google Places API,getAutocompletePredictions返回状态'PLACES_API_ACCESS_NOT_CONFIGURED'

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

  • Nirzon,您能否澄清一下如何启用Android版Place SDK?启用API并查询"Place SDK for Android"时,Google仅返回"Places API",它会一直向我提供PLACES_API_ACCESS_NOT_CONFIGURED 9003错误.谢谢 (4认同)

Kap*_*put 25

我一步一步的解决方案:

在此输入图像描述