Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

android - Couldn't connect to Google API client

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() + "
" +
                "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}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...