장소 사진

Android용 Places SDK를 사용하여 애플리케이션에 표시할 장소 사진을 요청할 수 있습니다. 사진 서비스에서 반환되는 사진은 비즈니스 소유자 및 사용자 제공 사진을 비롯한 다양한 소스에서 가져옵니다. 장소의 이미지를 가져오려면 다음 단계를 따라야 합니다.

  1. Place 객체를 가져옵니다 (fetchPlace() 또는 findCurrentPlace() 사용). 요청에 PHOTO_METADATAS 필드를 포함해야 합니다.
  2. FetchPlaceRequestOnSuccessListener에서 FetchPhotoRequest을 추가하고 원하는 경우 최대 높이 및 너비를 픽셀 단위로 지정합니다. 사진의 최대 너비 또는 높이는 1,600픽셀입니다.
  3. OnSuccessListener를 추가하고 FetchPhotoResponse에서 비트맵을 가져옵니다.

장소 사진 가져오기

다음 예는 장소 사진을 가져오는 방법을 보여줍니다.

자바


// 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(500) // Optional.
        .setMaxHeight(300) // Optional.
        .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.
        }
    });
});

      

Kotlin


// Define a Place ID.
val placeId = "INSERT_PLACE_ID_HERE"

// Specify fields. Requests for photos must always have the PHOTO_METADATAS field.
val fields = listOf(Place.Field.PHOTO_METADATAS)

// Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())
val placeRequest = FetchPlaceRequest.newInstance(placeId, fields)

placesClient.fetchPlace(placeRequest)
    .addOnSuccessListener { response: FetchPlaceResponse ->
        val place = response.place

        // Get the photo metadata.
        val metada = place.photoMetadatas
        if (metada == null || metada.isEmpty()) {
            Log.w(TAG, "No photo metadata.")
            return@addOnSuccessListener
        }
        val photoMetadata = metada.first()

        // Get the attribution text.
        val attributions = photoMetadata?.attributions

        // Create a FetchPhotoRequest.
        val photoRequest = FetchPhotoRequest.builder(photoMetadata)
            .setMaxWidth(500) // Optional.
            .setMaxHeight(300) // Optional.
            .build()
        placesClient.fetchPhoto(photoRequest)
            .addOnSuccessListener { fetchPhotoResponse: FetchPhotoResponse ->
                val bitmap = fetchPhotoResponse.bitmap
                imageView.setImageBitmap(bitmap)
            }.addOnFailureListener { exception: Exception ->
                if (exception is ApiException) {
                    Log.e(TAG, "Place not found: " + exception.message)
                    val statusCode = exception.statusCode
                    TODO("Handle error with given status code.")
                }
            }
    }

      

기여 분석

대부분의 경우 장소 사진은 저작자 표시 없이 사용할 수 있거나 필수 저작자 표시가 이미지의 일부로 포함됩니다. 그러나 반환된 PhotoMetadata 인스턴스에 저작자 표시가 포함된 경우 이미지를 표시할 때마다 애플리케이션에 추가 속성을 포함해야 합니다. 자세한 내용은 기여 분석 표시를 참고하세요.

사용량 및 결제

Places Photo SKU는 fetchPhoto() 호출에 대해 요금이 청구됩니다. 자세한 내용은 사용량 및 결제 페이지를 참고하세요.