我无法获取最后的已知位置。 我在 Google 控制台中启用了 Geocoding API 和 Google 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}”
更新
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 和 onConnectionFailed 不调用。
我也用 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 控制台中启用。
关于android - 无法连接到 Google API 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30650231/