【发布时间】:2018-07-21 05:02:08
【问题描述】:
在一个片段中,我实现了一个 Google PlaceAutoCompleteFragment。选择地点后,我想将该地点的图像上传到 Parse 服务器,所以我一直关注this guide。
在 OnCreateView() 中,我已经初始化了 GeoDataClient mGeoDataClient 使用
mGeoDataClient = Places.getGeoDataClient(getActivity());
我将正确的 placeId 传递给以下方法,调试器说 photoMetadataResponse 是 zzu@6303(我认为这没问题?)。似乎 onComplete 永远不会被执行,并且 bitmapArray 最后的大小为 0,因此 bitmap 返回为 null。
// Request photos and metadata for the specified place.
private Bitmap getPhotos(String placeId) {
final ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
final Task<PlacePhotoMetadataResponse> photoMetadataResponse = mGeoDataClient.getPlacePhotos(placeId);
photoMetadataResponse.addOnCompleteListener(new OnCompleteListener<PlacePhotoMetadataResponse>() {
@Override
public void onComplete(@NonNull Task<PlacePhotoMetadataResponse> task) {
// Get the list of photos.
PlacePhotoMetadataResponse photos = task.getResult();
// Get the PlacePhotoMetadataBuffer (metadata for all of the photos).
PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata();
// Get the first photo in the list.
PlacePhotoMetadata photoMetadata = photoMetadataBuffer.get(0);
// Get the attribution text.
CharSequence attribution = photoMetadata.getAttributions();
// Get a full-size bitmap for the photo.
Task<PlacePhotoResponse> photoResponse = mGeoDataClient.getPhoto(photoMetadata);
photoResponse.addOnCompleteListener(new OnCompleteListener<PlacePhotoResponse>() {
@Override
public void onComplete(@NonNull Task<PlacePhotoResponse> task) {
PlacePhotoResponse photo = task.getResult();
Bitmap bitmap = photo.getBitmap();
bitmapArray.add(bitmap); // Add a bitmap
}
});
}
});
return bitmapArray.get(0);
}
任何建议将不胜感激!
【问题讨论】:
标签: java android android-fragments google-places-api