use of com.google.android.libraries.places.api.net.FetchPhotoRequest in project android-places-demos by googlemaps.
the class PlacePhotosActivity method getPlacePhoto.
private void getPlacePhoto() {
// [START maps_places_get_place_photos]
// Define a Place ID.
final String placeId = "INSERT_PLACE_ID_HERE";
// Specify fields. Requests for photos must always have the PHOTO_METADATAS field.
final List<Place.Field> fields = Collections.singletonList(Place.Field.PHOTO_METADATAS);
// Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())
final FetchPlaceRequest placeRequest = FetchPlaceRequest.newInstance(placeId, fields);
placesClient.fetchPlace(placeRequest).addOnSuccessListener((response) -> {
final Place place = response.getPlace();
// Get the photo metadata.
final List<PhotoMetadata> metadata = place.getPhotoMetadatas();
if (metadata == null || metadata.isEmpty()) {
Log.w(TAG, "No photo metadata.");
return;
}
final PhotoMetadata photoMetadata = metadata.get(0);
// Get the attribution text.
final String attributions = photoMetadata.getAttributions();
// Create a FetchPhotoRequest.
final FetchPhotoRequest photoRequest = FetchPhotoRequest.builder(photoMetadata).setMaxWidth(// Optional.
500).setMaxHeight(// Optional.
300).build();
placesClient.fetchPhoto(photoRequest).addOnSuccessListener((fetchPhotoResponse) -> {
Bitmap bitmap = fetchPhotoResponse.getBitmap();
imageView.setImageBitmap(bitmap);
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
final ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + exception.getMessage());
final int statusCode = apiException.getStatusCode();
// TODO: Handle error with given status code.
}
});
});
// [END maps_places_get_place_photos]
}
Aggregations