GoogleApiClient 未配置为使用此调用所需的 API

GoogleApiClient is not configured to use the API required for this call

我正在尝试使用 Google Places API.

获取某个地点的纬度和经度

我正在关注这个例子:Google Directions Android

我这样配置客户端:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

但是这里:

PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
                    .getPlaceById(mGoogleApiClient, placeId);

我收到以下错误:

java.lang.IllegalArgumentException: GoogleApiClient is not configured to use the API required for this call.

我该如何解决?

我在 Google API 控制台上激活了 APIs,我认为我配置正确,就像示例一样。

因此,在与@Daniel 讨论后,解决方案是使用两个不同的 GoogleApiClient 实例:一个用于 LocationServices API,另一个用于 Places API.

只需如下所示创建两个 GoogleApiClient 实例并相应地使用:

 GoogleApiClient mGoogleApiClient1,mGoogleApiClient2;

        mGoogleApiClient1 = new GoogleApiClient.Builder(this)
        .addApi(Places.PLACE_DETECTION_API)
        .addApi(LocationServices.API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();

        mGoogleApiClient2 = new GoogleApiClient.Builder(this)
        .addApi(Places.GEO_DATA_API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();