android - 无法连接到 Google API 客户端

标签 android google-play-services android-geofence

我无法获取最后的已知位置。 我在 Google 控制台中启用了 Geocoding APIGoogle Places API for Android。 我将 api key 添加到 list 文件:

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_api_key" />

但我不断在控制台中收到一条消息:“无法连接到 Google API 客户端:ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}


更新

I use google sample

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
}

@Override
public void onConnected(Bundle connectionHint) {
    Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        Toast.makeText(this, "Latitude = " + mLastLocation.getLatitude() + "\n" +
                "Longitude = " + mLastLocation.getLongitude(), Toast.LENGTH_LONG).show();
    }
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    Toast.makeText(this, connectionResult.toString(), Toast.LENGTH_LONG).show();
}

onConnectedonConnectionFailed 不调用。

我也用 Android-ReactiveLocation 但两种方法都输出到控制台:Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}

最佳答案

我遇到了同样的问题

Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}

因为 Google Places API for Android 未在 API 控制台中启用。

https://developers.google.com/places/android/signup

关于android - 无法连接到 Google API 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30650231/

相关文章:

android - 有没有办法在 Android SDK 模拟器中获得可复制粘贴的调试输出?

按下后退按钮后,Android App 在 "launched"时打开第二个实例

android - MIME 类型从 "image/jpeg"切换为 "image/png"

java - 为什么 Google 地理围栏在我的 Android 应用程序中不起作用?

Android 11 用户无法授予后台位置权限?

android - 从一项 Activity 到另外两项

java - 如何将 .so 文件打包到 jar 中?

android - google-play-services lib 未使用 stub 未编译

android - Fit API 在 debup.apk 中有效,但从 Play 商店安装时无效

android - 在后台服务中创建地理围栏