Migrasi ke Foto Tempat (Baru)

Places SDK for iOS mendukung Place Photo yang sudah ada. Jika Anda sudah terbiasa dengan Foto Tempat yang sudah ada, Foto Tempat versi baru akan membuat perubahan berikut:

  • Menggunakan model penetapan harga baru. Guna mendapatkan informasi harga untuk semua API, lihat Harga untuk Places SDK for iOS (Baru).

  • Place Photo yang ada mendukung ukuran foto maksimum 1600x1600 piksel. Place Photo (Baru) mendukung ukuran hingga 4800x4800 piksel.

  • Untuk membuat permintaan, panggil metode GMSPlacesClient lookUpPhotosForPlaceID: baru, dengan meneruskan ID tempat sebagai string.

  • Teruskan callback jenis GMSPlacePhotoMetadataResultCallback ke permintaan untuk menangani respons.

  • Setiap foto dalam respons direpresentasikan oleh instance GMSPlacePhotoMetadata. Untuk Places SDK for iOS (Baru), instance GMSPlacePhotoMetadata berisi kolom authorAttribution baru yang direpresentasikan oleh class GMSPlaceAuthorAttribution baru.

    Jika instance GMSPlacePhotoMetadata yang ditampilkan menyertakan attributions atau authorAttribution, 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 = photos.first else { return }

  // Request individual photos in the response list
  let fetchPhotoRequest = GMSFetchPhotoRequest(metadata: photoMetadata, maxSize: CGSizeMake(4800, 4800)
  placesClient.fetchPhoto(fetchPhotoRequest: fetchPhotoRequest, callback: {
    (photoURL: URL?, error: Error?) in
      guard let photoURL, error == nil else { return }
      print("Photo URL: \(photoURL)")
  })
};

Objective-C

// A hotel in Saigon with an attribution.
NSString *placeID = @"ChIJV4k8_9UodTERU5KXbkYpSYs";

[placesClient lookUpPhotosForPlaceID:placeID callback: (GMSPlacePhotoMetadataList *list, NSError *error) {
  GMSPlacePhotoMetadata *photoMetadata = [list firstObject];

  if (photoMetadata == nil) { return }

  // Request individual photos in the response list
  GMSFetchPhotoRequest *fetchPhotoRequest = [[GMSFetchPhotoRequest alloc] initWithPhotoMetadata:photoMetadata maxSize:CGSizeMake(4800, 4800)];
  [placesClient fetchPhoto:fetchPhotoRequest, callback: ^(NSURL *_Nullable photoURL, NSError *_Nullable error) {
    if (error == null) {
      NSLog(@"Photo URL: %@", photoURL)
    }
  }];
}];