Place Photos (New)

Select platform: Android iOS Web Service
European Economic Area (EEA) developers

Place Photos (New) lets you add high quality photographic content to your application. Place Photos gives you access to the millions of photos stored in the Places database. Place Photos returns a URI to a bitmap image. The bitmap image has a maximum size of 4800 by 4800 pixels.

Place Photos requests

To retrieve an image for a place:

  1. Use Place Details (New) to fetch a Place object using fetchPlace() . Be sure to include the Place.Field PHOTO_METADATAS field in the list of fields to include in the response Place object.
  2. In the OnSuccessListener for your FetchPlaceResponse , call Place.getPhotoMetadas() to get the photo metadata object of type PhotoMetadata from the response Place object.
  3. Create a FetchResolvedPhotoUriRequest object to make the request and pass the photo metadata object, as well values for maximum height, maximum width, or both.
  4. Use PlacesClient.fetchResolvedPhotoUri() to request the photo URI.
  5. Add an OnSuccessListener and get the photo URI from the FetchResolvedPhotoUriResponse object.

Required parameters

The required parameters for FetchResolvedPhotoUriRequest are:

  • The metadata object of the photo to return.

  • Maximum height or maximum width

    Specifies the maximum height and width, in pixels, of the image to return. If the image is smaller than the values specified, the original image will be returned. If the image is larger in either dimension, it will be scaled to match the smaller of the two dimensions, restricted to its original aspect ratio. Both the maximum height and maximum width properties accept an integer between 1 and 4800. You must specify maximum height, maximum width, or both.

    • To set the maximum height parameter, call the setMaxHeight() method when building the FetchResolvedPhotoUriRequest object.
    • To set the maximum width parameter, call the setMaxWidth() method when building the FetchResolvedPhotoUriRequest object.

Place Photos examples

The following example demonstrates getting a place photo URI.

 // 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 and author attributions. 
  
 final 
  
 String 
  
 attributions 
  
 = 
  
 photoMetadata 
 . 
 getAttributions 
 (); 
  
 final 
  
 AuthorAttributions 
  
 authorAttributions 
  
 = 
  
 photoMetadata 
 . 
 getAuthorAttributions 
 (); 
  
 // Create a FetchResolvedPhotoUriRequest. 
  
 final 
  
 FetchResolvedPhotoUriRequest 
  
 photoRequest 
  
 = 
  
 FetchResolvedPhotoUriRequest 
 . 
 builder 
 ( 
 photoMetadata 
 ) 
  
 . 
 setMaxWidth 
 ( 
 500 
 ) 
  
 . 
 setMaxHeight 
 ( 
 300 
 ) 
  
 . 
 build 
 (); 
  
 // Request the photo URI 
  
 placesClient 
 . 
 fetchResolvedPhotoUri 
 ( 
 photoRequest 
 ). 
 addOnSuccessListener 
 (( 
 fetchResolvedPhotoUriResponse 
 ) 
  
 -> 
  
 { 
  
 Uri 
  
 uri 
  
 = 
  
 fetchResolvedPhotoUriResponse 
 . 
 getUri 
 (); 
  
 RequestOptions 
  
 requestOptions 
  
 = 
  
 new 
  
 RequestOptions 
 (). 
 override 
 ( 
 Target 
 . 
 SIZE_ORIGINAL 
 ); 
  
 Glide 
 . 
 with 
 ( 
 this 
 ). 
 load 
 ( 
 uri 
 ). 
 apply 
 ( 
 requestOptions 
 ). 
 into 
 ( 
 imageView 
 ); 
  
 }). 
 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. 
  
 } 
  
 }); 
 }); 

Attributions

In most cases, place photos can be used without attribution, or will have the required attribution included as part of the image. However, the photo metadata object, of type PhotoMetadata , can contain either of two types of additional attributions:

If the returned PhotoMetadata object includes either type of attribution, you must include the attribution in your application wherever you display the image. For more information, see Displaying Attributions .

Create a Mobile Website
View Site in Mobile | Classic
Share by: