Android용 Places SDK를 사용하여 애플리케이션에 표시할 장소 사진을 요청할 수 있습니다. 사진 서비스에서 반환되는 사진은 비즈니스 소유자 및 사용자 제공 사진을 비롯한 다양한 출처에서 가져온 것입니다.
Android용 Places SDK는 최대 크기가 1,600x1,600픽셀인 비트맵 이미지를 반환합니다.
사진 검색 절차
장소의 이미지를 검색하려면 다음 단계를 따르세요.
- 장소 세부정보를 사용하여
Place
객체를 가져옵니다 (fetchPlace()
또는findCurrentPlace()
사용). 응답Place
객체에 포함할 필드 목록에Place.Field PHOTO_METADATAS
필드를 포함해야 합니다. FetchPlaceResponse
또는FindCurrentPlaceResponse
의OnSuccessListener
에서Place.getPhotoMetadas()
를 사용하여 응답Place
객체에서PhotoMetadata
유형의 사진 메타데이터 객체를 가져옵니다.FetchPhotoRequest
객체를 만들고 원하는 경우 최대 높이와 너비 (픽셀 단위)를 지정합니다. 사진의 최대 너비 또는 높이는 1,600픽셀입니다.PlacesClient.fetchPhoto()
를 사용하여 사진 비트맵을 요청합니다.OnSuccessListener
를 추가하고FetchPhotoResponse
에서 사진을 가져옵니다.
사진 가져오기
다음 예는 장소 사진을 가져오는 방법을 보여줍니다.
// 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.") } } }
// 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. } }); });
기여 분석
대부분의 경우 장소 사진은 저작자 표시 없이 사용할 수 있거나 필수 저작권 표시가 이미지의 일부로 포함되어 있습니다. 그러나 PhotoMetadata
유형의 사진 메타데이터 객체는 다음 두 가지 유형의 추가 저작자를 포함할 수 있습니다.
- 기여 분석:
PhotoMetadata.getAttributions()
에서 액세스하는 기여 분석 문자열입니다. - AuthorAttributions:
PhotoMetadata.getAuthorAttributions()
에서 액세스하는AuthorAttributions
객체입니다.
반환된 PhotoMetadata
객체에 두 가지 유형의 저작자 표시가 포함된 경우 이미지를 표시할 때마다 애플리케이션에 저작자 표시를 포함해야 합니다. 자세한 내용은 저작자 표시 표시를 참고하세요.
사용량 및 결제
Places Photo SKU는 fetchPhoto()
호출에 대해 요금이 청구됩니다.
자세한 내용은 사용량 및 결제 페이지를 참고하세요.