Place Photos(従来版)

欧州経済領域(EEA)のデベロッパー

Places SDK for Android(以前のバージョン)を使用すると、アプリに表示するスポットの写真をリクエストできます。フォトサービスによって返される写真の提供元は、お店やサービスの所有者、ユーザーの投稿などさまざまです。

Places SDK for Android(以前のバージョン)は、最大サイズが 1,600 x 1,600 ピクセルのビットマップ画像を返します。

写真の取得プロセス

場所の画像を取得するには:

  1. Place Details(レガシー)を使用して、Place オブジェクトを取得します(fetchPlace() を使用)。 レスポンスの Place オブジェクトに含めるフィールドのリストに Place.Field PHOTO_METADATAS フィールドを含めるようにしてください。
  2. FetchPlaceResponse の OnSuccessListener で、Place.getPhotoMetadas() を使用して、レスポンス Place オブジェクトから PhotoMetadata 型の写真メタデータ オブジェクトを取得します。
  3. FetchPhotoRequest オブジェクトを作成します。必要に応じて、高さと幅の最大値(ピクセル単位)を指定します。写真の最大幅または最大高さは 1,600 ピクセルです。
  4. PlacesClient.fetchPhoto() を使用して、写真のビットマップをリクエストします。
  5. OnSuccessListener を追加して、FetchPhotoResponse から写真を取得します。

写真を取得する

次の例は、プレイスの写真を取得する方法を示しています。

Kotlin

// Define a Place ID.
val placeId = PlaceIdProvider.getRandomPlaceId()

// 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 metadata = place.photoMetadatas
        if (metadata == null || metadata.isEmpty()) {
            Log.w(TAG, "No photo metadata.")
            return@addOnSuccessListener
        }
        val photoMetadata = metadata.first()

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

        binding.placePhotosAttributions.text = attributions

        // Create a FetchResolvedPhotoUriRequest.
        val photoRequest = FetchResolvedPhotoUriRequest.builder(photoMetadata)
            .setMaxWidth(500) // Optional.
            .setMaxHeight(300) // Optional.
            .build()
        placesClient.fetchResolvedPhotoUri(photoRequest)
            .addOnSuccessListener { fetchPhotoResponse ->
                val photoUri = fetchPhotoResponse.uri
                Glide.with(this)
                    .load(photoUri)
                    .into(binding.placePhotosResult)
            }.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.
                }
            }
    }

      

Java

// Define a Place ID.
final String placeId = PlaceIdProvider.getRandomPlaceId();

// 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();
                    binding.placePhotosAttributions.setText(attributions);

                    // Create a FetchResolvedPhotoUriRequest.
                    final FetchResolvedPhotoUriRequest photoRequest =
                            FetchResolvedPhotoUriRequest.builder(photoMetadata)
                                    .setMaxWidth(500) // Optional.
                                    .setMaxHeight(300) // Optional.
                                    .build();
                    placesClient
                            .fetchResolvedPhotoUri(photoRequest)
                            .addOnSuccessListener(
                                    (fetchPhotoResponse) -> {
                                        Glide.with(this)
                                                .load(fetchPhotoResponse.getUri())
                                                .into(binding.placePhotosResult);
                                    })
                            .addOnFailureListener(
                                    (exception) -> {
                                        if (exception instanceof ApiException) {
                                            ApiException apiException =
                                                    (ApiException) exception;
                                            Log.e(
                                                    TAG,
                                                    "Place not found: "
                                                            + exception.getMessage());
                                            final int statusCode =
                                                    apiException.getStatusCode();
                                            // TODO: Handle error with given status code.
                                        }
                                    });
                });

      

帰属表示

ほとんどの場合、スポットの写真は帰属情報なしで使用できるか、必要な帰属情報が画像内にあらかじめ記載されています。ただし、PhotoMetadata 型の写真メタデータ オブジェクトには、次の 2 種類の追加の帰属情報のいずれかを含めることができます。

返された PhotoMetadata オブジェクトにいずれかのタイプの帰属情報が含まれる場合は、アプリケーション内でその画像を表示するすべての箇所で、帰属情報として組み込む必要があります。詳しくは、帰属情報の表示をご覧ください。

使用量と請求額

fetchPhoto() を呼び出すと、Place Photos(以前のバージョン) SKU が課金されます。詳細については、使用量と課金のページをご覧ください。