我一直在尝试测试Google Places API的getCurrentPlace()方法。当我第一次测试它时,它没有问题,但现在突然停止工作。我卸载了应用程序,删除了代码并从文档中重新粘贴,关闭了Android Studio。我不知道发生了什么问题,并且日志没有发生错误,他们只是不记录过去记录的内容。getCurrentPlace onResult不返回结果
View.OnClickListener getNearbyPlaces = new View.OnClickListener() {
@Override
public void onClick(View v) {
places = new FindNearbyPlaces();
placesArray = new ArrayList<>();
try {
placesArray = places.findNearbyPlaces(mCurrentLocation);
} catch (Exception e) {
e.printStackTrace();
}
for (PlacesAttributes place : placesArray) {
Log.i("Name: ", place.getName());
Log.i("Lat: ", String.valueOf(place.getLat()));
Log.i("Lng: ", String.valueOf(place.getLng()));
}
if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi
.getCurrentPlace(mGoogleApiClient, null);
result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
@Override
public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
Log.i("help", "");
for (PlaceLikelihood placeLikelihood : likelyPlaces) {
Log.i("Place", String.format("Place '%s' has likelihood: %g",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
likelyPlaces.release();
}
});
}
};
这是我有的代码块。在开始的前三个日志语句运行他们的过程,但onResult中的日志语句不,甚至没有Log.i(“帮助”,“”)。我有开始日志声明他们在什么时候工作,所以他们不应该是一个问题。
我没有检查,只是为了确保。但是你看不到,这是我的道歉,getCurrentPlace()之前的上述语句制定了我的另一个功能,它通过URL执行PlaceSearch,这样我就可以通过日志访问我的位置并返回附近的地方。 –