You're all set!

To start developing, please head over to our developer documentation.

Activate the Google Places API for Android

To get you started we'll guide you through the Google Developers Console to do a few things first:

  1. Create or choose a project
  2. Activate the Google Places API for Android
  3. Create appropriate keys
Continue

Place Photos

You can use the Google Places API for Android to request place photos to display in your application. Photos returned by the photos service come from a variety of sources, including business owners and user-contributed photos. To retrieve images for a place, you must take the following steps:

  1. Call GeoDataClient.getPlacePhotos(), passing a string with a place ID. This returns a PlacePhotoMetadataResponse instance.
  2. Add a completion listener for the PlacePhotoMetadataResponse instance.
  3. In the completion listener, call getResult() on the response task to get the list of photos.
  4. Call getPhotoMetadata() on the PlacePhotoMetadataResponse instance to get a PlacePhotoMetadataBuffer holding a list of PlacePhotoMetadata instances (one for each photo).
  5. Call get() on the PlacePhotoMetadataBuffer instance, passing an integer to retrieve the PlacePhotoMetadata instance at the given index.

  6. To return attribution text, call PlacePhotoMetadata.getAttributions() on a PlacePhotoMetadata instance.
  7. To return a bitmap image:
    1. Call GeoDataClient.getPhoto(), passing a PlacePhotoMetadata instance.
    2. Add a completion listener for PlacePhotoResponse.
    3. In the completion listener, call getResult() on the response task to get a PlacePhotoResponse.
    4. Call getBitmap() on the PlacePhotoResponse to get the bitmap.

Get photos for a place

The following simplified code snippet demonstrates getting the list of photos for a place, then getting the bitmap and attribution text for the first photo in the list.

// Request photos and metadata for the specified place.
private void getPhotos() {
    final String placeId = "ChIJa147K9HX3IAR-lwiGIQv9i4";
    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();
                }
            });
        }
    });
}

Attributions

In most cases, place photos can be used without attribution, or will have the required attribution included as part of the image. However, if the returned PlacePhotoMetadata instance includes an attribution, you must include the additional attribution in your application wherever you display the image. For more information, see Displaying Attributions.

Usage limits

Retrieving an image costs one unit of quota; there are no usage limits for retrieving photo metadata. See the documentation on usage limits.

Send feedback about...

location_on
Google Places API for Android