我一直在嘗試測試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,這樣我就可以通過日誌訪問我的位置並返回附近的地方。 –