我正在尝试使用Places API for Android来获取当前位置。我使用版本SHA1密钥和正确的软件包名称获得了一个API密钥。但是,在运行应用程序时,它会给出
{statusCode=PLACES_API_INVALID_APP, resolution=null}
错误,无法获取当前位置的详细信息。 这是我的代码:
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(this, this)
.build();
if (mGoogleApiClient.isConnected()) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSION_REQUEST_CODE);
} else {
callPlaceDetectionApi();
}
}
private void callPlaceDetectionApi() throws SecurityException {
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(@NonNull PlaceLikelihoodBuffer likelyPlaces) {
final CharSequence thirdPartyAttributions =
likelyPlaces.getAttributions();
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i(LOG_TAG, String.format("Place '%s' with " +
"likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
}
任何有关解决此问题的帮助都将受到赞赏。
答案 0 :(得分:0)
我在不使用SHA1释放密钥的情况下生成了一个新密钥并使用了它,这解决了这个问题。