Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void loadPlaceImage(final ImageView imageView, String placeId) {
- /**
- * Load a bitmap from the photos API asynchronously
- * by using buffers and result callbacks.
- */
- Places.GeoDataApi.getPlacePhotos(mGoogleApiClient, placeId)
- .setResultCallback(new ResultCallback<PlacePhotoMetadataResult>() {
- @Override
- public void onResult(PlacePhotoMetadataResult photos) {
- if (!photos.getStatus().isSuccess()) {
- Log.d(TAG, "Couldn't receive photos bundle successfully.");
- return;
- }
- Log.d(TAG, "Photo bundle received successfully");
- PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata();
- if (photoMetadataBuffer.getCount() > 0) {
- // Display the first bitmap in an ImageView in the size of the view
- photoMetadataBuffer.get(0)
- .getScaledPhoto(mGoogleApiClient, imageView.getWidth(),
- imageView.getHeight())
- .setResultCallback(new ResultCallback<PlacePhotoResult>() {
- @Override
- public void onResult(PlacePhotoResult placePhotoResult) {
- if (!placePhotoResult.getStatus().isSuccess()) {
- Log.d(TAG, "Couldn't retrieve the photo successfully.");
- return;
- }
- Log.d(TAG, "Successfully retrieved photo from photo bundle.");
- imageView.setImageBitmap(placePhotoResult.getBitmap());
- }
- });
- } else {
- Log.d(TAG, "0 images in the buffer.");
- }
- photoMetadataBuffer.release();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement