无法连接到Google API客户端 [英] Couldn't connect to Google API client

查看:641
本文介绍了无法连接到Google API客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获取最后一个已知位置。
我在Google控制台中启用了地理编码API 适用于Android的Google Places API
我在清单文件中添加了api key:

 < 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 client:ConnectionResult {statusCode = API_UNAVAILABLE,resolution = null}





$ b UPDATE



我使用google示例

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

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

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

onConnected onConnectionFailed 不要打电话。



此外,我还使用 Android-ReactiveLocation
,但这两种方法都输出到控制台:无法连接到Google API客户端:ConnectionResult {statusCode = API_UNAVAILABLE,resolution = null}

解决方案

我遇到同样的问题

 无法连接到Google API客户端:ConnectionResult {statusCode = API_UNAVAILABLE,resolution = null} 

因为 Google Android应用商店API 未在API控制台中启用。



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


I can't fetch last known location. I have enabled Geocoding API and Google Places API for Android in google console. I added api key to manifest file:

<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" />

but I keep getting a message in the console: "Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}"


UPDATE

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();
}

onConnected and onConnectionFailed do not call.

And also I use Android-ReactiveLocation but both methods are output to the console: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}

解决方案

I had the same problem

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

because Google Places API for Android was not enabled in the API Console.

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

这篇关于无法连接到Google API客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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