【发布时间】:2015-08-19 10:36:26
【问题描述】:
我无法获取最后一个已知位置。 我在谷歌控制台中启用了 Geocoding API 和 Google Places API for Android。 我在清单文件中添加了 api 密钥:
<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 但两种方法都输出到控制台:无法连接到 Google API 客户端:ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}
【问题讨论】:
-
请发布您的代码。
标签: android google-play-services android-geofence