Place Photos (Baru) memungkinkan Anda menambahkan konten fotografi berkualitas tinggi ke aplikasi Anda. Foto Tempat memberi Anda akses ke jutaan foto yang tersimpan dalam database Places. Place Photos menampilkan URI ke gambar bitmap. Gambar bitmap memiliki ukuran maksimum 4800 x 4800 piksel.
Permintaan Place Photos
Untuk mengambil gambar suatu tempat:
Gunakan Place Details (Baru) untuk mengambil objek Place menggunakan
fetchPlace().
Pastikan untuk menyertakan kolom Place.Field PHOTO_METADATAS dalam daftar kolom yang akan disertakan dalam objek respons Place.
Buat objek FetchResolvedPhotoUriRequest untuk membuat permintaan dan teruskan objek metadata foto, serta nilai untuk tinggi maksimum, lebar maksimum, atau keduanya.
Menentukan tinggi dan lebar maksimum gambar yang akan ditampilkan, dalam piksel. Jika gambar lebih kecil dari nilai yang ditentukan, gambar asli akan ditampilkan. Jika gambar lebih besar dalam salah satu dimensi, gambar akan diskalakan agar sesuai dengan dimensi yang lebih kecil, dan dibatasi pada rasio aspek aslinya. Properti tinggi maksimum dan lebar maksimum menerima bilangan bulat antara 1 dan 4800. Anda harus menentukan tinggi maksimum, lebar maksimum, atau keduanya.
Untuk menetapkan parameter tinggi maksimum, panggil metode setMaxHeight() saat membangun objek FetchResolvedPhotoUriRequest.
Untuk menetapkan parameter lebar maksimum, panggil metode setMaxWidth() saat membangun objek FetchResolvedPhotoUriRequest.
Contoh Place Photos
Contoh berikut menunjukkan cara mendapatkan URI foto tempat.
// Define a Place ID.finalStringplaceId="INSERT_PLACE_ID_HERE";// Specify fields. Requests for photos must always have the PHOTO_METADATAS field.finalList<Place.Field>fields=Collections.singletonList(Place.Field.PHOTO_METADATAS);// Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())finalFetchPlaceRequestplaceRequest=FetchPlaceRequest.newInstance(placeId,fields);placesClient.fetchPlace(placeRequest).addOnSuccessListener((response)->{finalPlaceplace=response.getPlace();// Get the photo metadata.finalList<PhotoMetadata>metadata=place.getPhotoMetadatas();if(metadata==null||metadata.isEmpty()){Log.w(TAG,"No photo metadata.");return;}finalPhotoMetadataphotoMetadata=metadata.get(0);// Get the attribution text and author attributions.finalStringattributions=photoMetadata.getAttributions();finalAuthorAttributionsauthorAttributions=photoMetadata.getAuthorAttributions();// Create a FetchResolvedPhotoUriRequest.finalFetchResolvedPhotoUriRequestphotoRequest=FetchResolvedPhotoUriRequest.builder(photoMetadata).setMaxWidth(500).setMaxHeight(300).build();// Request the photo URIplacesClient.fetchResolvedPhotoUri(photoRequest).addOnSuccessListener((fetchResolvedPhotoUriResponse)->{Uriuri=fetchResolvedPhotoUriResponse.getUri();RequestOptionsrequestOptions=newRequestOptions().override(Target.SIZE_ORIGINAL);Glide.with(this).load(uri).apply(requestOptions).into(imageView);}).addOnFailureListener((exception)->{if(exceptioninstanceofApiException){finalApiExceptionapiException=(ApiException)exception;Log.e(TAG,"Place not found: "+exception.getMessage());finalintstatusCode=apiException.getStatusCode();// TODO: Handle error with given status code.}});});
Atribusi
Umumnya, foto tempat dapat digunakan tanpa atribusi, atau atribusi yang diperlukan
akan disertakan sebagai bagian dari gambar. Namun, objek metadata foto, dengan jenis
PhotoMetadata,
dapat berisi salah satu dari dua jenis atribusi tambahan:
Jika objek PhotoMetadata yang ditampilkan menyertakan salah satu jenis atribusi, Anda harus
menyertakan atribusi dalam aplikasi di mana pun Anda menampilkan gambar. Untuk mengetahui informasi selengkapnya, lihat Menampilkan Atribusi.
[null,null,["Terakhir diperbarui pada 2025-08-30 UTC."],[[["\u003cp\u003ePlace Photos (New) allows you to access and display millions of photos from the Google Places database in your application.\u003c/p\u003e\n"],["\u003cp\u003eTo retrieve a place photo, you must first fetch a \u003ccode\u003ePlace\u003c/code\u003e object using Place Details (New) with the \u003ccode\u003ePHOTO_METADATAS\u003c/code\u003e field, then use this metadata to request the photo URI via the Places SDK.\u003c/p\u003e\n"],["\u003cp\u003ePhoto requests require specifying either a maximum width, maximum height, or both, for the returned image, with the maximum resolution being 4800x4800 pixels.\u003c/p\u003e\n"],["\u003cp\u003eWhile most Place Photos can be used without attribution, some may require displaying attributions obtained from the \u003ccode\u003ePhotoMetadata\u003c/code\u003e object alongside the image.\u003c/p\u003e\n"]]],[],null,["# Place Photos (New)\n\nSelect platform: [Android](/maps/documentation/places/android-sdk/place-photos \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/place-photos \"View this page for the iOS platform docs.\") [Web Service](/maps/documentation/places/web-service/place-photos \"View this page for the Web Service platform docs.\")\n\n\u003cbr /\u003e\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nPlace Photos (New) lets you add high quality photographic content to your\napplication. Place Photos gives you access to the millions of photos stored in\nthe Places database. Place Photos returns a URI to a bitmap image. The bitmap\nimage has a maximum size of 4800 by 4800 pixels.\n| **Note:** Place Photos (New) is available in Places SDK for Android version 3.4.0 and later. For more information, see [Choose your SDK\n| version](/maps/documentation/places/android-sdk/choose-sdk). For more information about using the Kotlin APIs added in version 4.0.0, see the [Reference\n| Overview](/maps/documentation/places/android-sdk/reference).\n\nPlace Photos requests\n---------------------\n\nTo retrieve an image for a place:\n\n1. Use [Place Details (New)](/maps/documentation/places/android-sdk/details-places) to fetch a `Place` object using [`fetchPlace()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesClient#fetchPlace(com.google.android.libraries.places.api.net.FetchPlaceRequest)). Be sure to include the `Place.Field PHOTO_METADATAS` field in the list of fields to include in the response `Place` object.\n2. In the [`OnSuccessListener`](https://developer.android.com/reference/com/google/android/play/core/tasks/OnSuccessListener) for your [`FetchPlaceResponse`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/FetchPlaceResponse), call [`Place.getPhotoMetadas()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place#getPhotoMetadatas()) to get the photo metadata object of type [`PhotoMetadata`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/PhotoMetadata) from the response `Place` object.\n3. Create a [`FetchResolvedPhotoUriRequest`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/FetchResolvedPhotoUriRequest.Builder) object to make the request and pass the photo metadata object, as well values for maximum height, maximum width, or both.\n4. Use [`PlacesClient.fetchResolvedPhotoUri()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesClient#fetchResolvedPhotoUri(com.google.android.libraries.places.api.net.FetchResolvedPhotoUriRequest)) to request the photo URI.\n5. Add an `OnSuccessListener` and get the photo URI from the [`FetchResolvedPhotoUriResponse`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/FetchResolvedPhotoUriResponse) object.\n\n| **Note:** For more information on initializing `PlacesClient`, see [Initialize the Places API client](/maps/documentation/places/android-sdk/config#connect-client).\n| You can use a [CancellationToken](/android/reference/com/google/android/gms/tasks/CancellationToken)\n| to attempt to cancel a request to any of the request classes (for example,\n| `FetchPlaceRequest`). Cancellation is done on a best-effort basis.\n| Once a cancellation request is issued, no response will be returned.\n| **Issuing a cancellation token does NOT guarantee that a particular request\n| will be cancelled, and you may still be charged for the request even if no\n| response is returned**.\n\nRequired parameters\n-------------------\n\nThe required parameters for\n[`FetchResolvedPhotoUriRequest`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/FetchResolvedPhotoUriRequest.Builder)\nare:\n\n-\n\n ### Photo metadata\n\n The metadata object of the photo to return.\n-\n\n ### Maximum height or maximum width\n\n\n 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.\n - To set the maximum height parameter, call the [setMaxHeight()](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/FetchResolvedPhotoUriRequest.Builder#public-abstract-fetchresolvedphotourirequest.builder-setmaxheight-integer-maxheight) method when building the `FetchResolvedPhotoUriRequest` object.\n - To set the maximum width parameter, call the [setMaxWidth()](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/net/FetchResolvedPhotoUriRequest.Builder#public-abstract-fetchresolvedphotourirequest.builder-setmaxwidth-integer-maxwidth) method when building the `FetchResolvedPhotoUriRequest` object.\n\nPlace Photos examples\n---------------------\n\nThe following example demonstrates getting a place photo URI. \n\n```java\n// Define a Place ID.\nfinal String placeId = \"INSERT_PLACE_ID_HERE\";\n\n// Specify fields. Requests for photos must always have the PHOTO_METADATAS field.\nfinal List\u003cPlace.Field\u003e fields = Collections.singletonList(Place.Field.PHOTO_METADATAS);\n\n// Get a Place object (this example uses fetchPlace(), but you can also use findCurrentPlace())\nfinal FetchPlaceRequest placeRequest = FetchPlaceRequest.newInstance(placeId, fields);\n\nplacesClient.fetchPlace(placeRequest).addOnSuccessListener((response) -\u003e {\n final Place place = response.getPlace();\n\n // Get the photo metadata.\n final List\u003cPhotoMetadata\u003e metadata = place.getPhotoMetadatas();\n if (metadata == null || metadata.isEmpty()) {\n Log.w(TAG, \"No photo metadata.\");\n return;\n }\n final PhotoMetadata photoMetadata = metadata.get(0);\n\n // Get the attribution text and author attributions.\n final String attributions = photoMetadata.getAttributions();\n final AuthorAttributions authorAttributions = photoMetadata.getAuthorAttributions();\n\n // Create a FetchResolvedPhotoUriRequest.\n final FetchResolvedPhotoUriRequest photoRequest = FetchResolvedPhotoUriRequest.builder(photoMetadata)\n .setMaxWidth(500)\n .setMaxHeight(300)\n .build();\n\n // Request the photo URI\n placesClient.fetchResolvedPhotoUri(photoRequest).addOnSuccessListener((fetchResolvedPhotoUriResponse) -\u003e {\n Uri uri = fetchResolvedPhotoUriResponse.getUri();\n RequestOptions requestOptions = new RequestOptions().override(Target.SIZE_ORIGINAL);\n Glide.with(this).load(uri).apply(requestOptions).into(imageView);\n }).addOnFailureListener((exception) -\u003e {\n if (exception instanceof ApiException) {\n final ApiException apiException = (ApiException) exception;\n Log.e(TAG, \"Place not found: \" + exception.getMessage());\n final int statusCode = apiException.getStatusCode();\n // TODO: Handle error with given status code.\n }\n });\n});\n```\n\nAttributions\n------------\n\nIn most cases, place photos can be used without attribution, or will have\nthe required attribution included as part of the image. However, the photo metadata object, of type\n[`PhotoMetadata`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/PhotoMetadata),\ncan contain either of two types of additional attributions:\n\n- **Attributions** , an attribution string accessed by [`PhotoMetadata.getAttributions()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/PhotoMetadata#public-abstract-string-getattributions).\n- **AuthorAttributions** , an [`AuthorAttributions`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/AuthorAttributions) object accessed by [`PhotoMetadata.getAuthorAttributions()`](/maps/documentation/places/android-sdk/reference/com/google/android/libraries/places/api/model/PhotoMetadata#public-abstract-authorattributions-getauthorattributions).\n\nIf the returned `PhotoMetadata` object includes either type of attribution, you must\ninclude the attribution in your application wherever you display the image. For more information,\nsee [Displaying Attributions](/maps/documentation/places/android-sdk/attributions#photos)."]]