Places SDK for iOS mendukung Foto Tempat (Lama). Jika Anda sudah familiar dengan Place Photo (Lama), Place Photo (Baru) melakukan perubahan berikut:
Menggunakan model harga baru. Untuk informasi harga semua API, lihat Harga Places SDK for iOS (Baru).
Tempat Foto (Lama) mendukung ukuran foto maksimum 1600 x 1600 piksel. Tempat Foto (Baru) mendukung ukuran hingga 4800 x 4800 piksel.
Untuk membuat permintaan, panggil metode
GMSPlacesClient fetchPhotoWithRequest:callback:
baru.Teruskan ke permintaan:
Instance class
GMSFetchPhotoRequest
baru yang menentukan semua parameter permintaan, termasuk ukuran gambar maksimum.Callback jenis
GMSPlacePhotoMetadataResultCallback
untuk menangani respons.
Setiap foto direpresentasikan oleh instance
GMSPlacePhotoMetadata
. Untuk Places SDK for iOS (Baru), instanceGMSPlacePhotoMetadata
berisi kolomauthorAttribution
baru yang diwakili oleh classGMSPlaceAuthorAttribution
baru.Jika instance
GMSPlacePhotoMetadata
yang ditampilkan menyertakanattributions
atauauthorAttribution
, Anda harus menyertakan atribusi ini dalam aplikasi di mana pun Anda menampilkan gambar. Lihat dokumentasi tentang atribusi.
Contoh permintaan
Contoh metode berikut mengambil ID tempat dan mendapatkan foto pertama dalam daftar yang ditampilkan. Anda dapat menggunakan metode ini sebagai template untuk metode yang akan dibuat di aplikasi Anda sendiri.
Swift
// A hotel in Saigon with an attribution. let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs" // Request list of photos for a place placesClient.lookUpPhotos(forPlaceID: placeID) { (photos, error) in guard let photoMetadata: GMSPlacePhotoMetadata = photos?.results[0] else { return } // Request individual photos in the response list let fetchPhotoRequest = GMSFetchPhotoRequest(photoMetadata: photoMetadata, maxSize: CGSizeMake(4800, 4800)) self.client.fetchPhoto(with: fetchPhotoRequest, callback: { (photoImage: UIImage?, error: Error?) in guard let photoImage, error == nil else { print("Handle photo error: ") return } print("Display photo Image: ") } ) }
Objective-C
// A hotel in Saigon with an attribution. NSString *placeID = @"ChIJV4k8_9UodTERU5KXbkYpSYs"; [placesClient lookUpPhotosForPlaceID:placeID callback: ^(GMSPlacePhotoMetadataList *list, NSError *error) { GMSPlacePhotoMetadata *photoMetadata = [list results][0]; // Request individual photos in the response list GMSFetchPhotoRequest *fetchPhotoRequest = [[GMSFetchPhotoRequest alloc] initWithPhotoMetadata:photoMetadata maxSize:CGSizeMake(4800, 4800)]; [placesClient fetchPhotoWithRequest:fetchPhotoRequest callback: ^(UIImage *_Nullable photoImage, NSError *_Nullable error) { if (error == nil) { // Display photo } }]; }];