Esegui la migrazione a Place Photo (novità)

L'SDK Places per iOS supporta l'attuale foto del luogo. Se hai dimestichezza con la foto del luogo esistente, la nuova versione di Place Photo apporta le seguenti modifiche:

  • Utilizza un nuovo modello di determinazione del prezzo. Per informazioni sui prezzi di tutte le API, vedi Prezzi per Places SDK for iOS (nuovi).

  • La foto del luogo esistente supportava una dimensione massima delle foto di 1600 x 1600 pixel. Place Photo (Nuova) supporta dimensioni fino a 4800 x 4800 pixel.

  • Per effettuare una richiesta, chiama il nuovo metodo GMSPlacesClient lookUpPhotosForPlaceID:, passando l'ID luogo come stringa.

  • Passa alla richiesta un callback di tipo GMSPlacePhotoMetadataResultCallback per gestire la risposta.

  • Ogni foto nella risposta è rappresentata da un'istanza GMSPlacePhotoMetadata. Per Places SDK for iOS (New), l'istanza GMSPlacePhotoMetadata contiene un nuovo campo authorAttribution rappresentato dalla nuova classe GMSPlaceAuthorAttribution.

    Se l'istanza GMSPlacePhotoMetadata restituita include attributions o authorAttribution, devi includere queste attribuzioni nell'applicazione ovunque mostri l'immagine. Consulta la documentazione sulle attribuzioni.

Esempio di richiesta

Il seguente metodo di esempio utilizza un ID luogo e ottiene la prima foto nell'elenco dei risultati restituiti. Puoi utilizzare questo metodo come modello per il metodo che creerai nella tua app.

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)
    }
  }];
}];