Places SDK for iOS supporta Place Photo (legacy). Se hai familiarità con Foto del luogo (legacy), Foto del luogo (nuova) apporta le seguenti modifiche:
Utilizza un nuovo modello di prezzi. Per informazioni sui prezzi di tutte le API, consulta Prezzi di Places SDK per iOS (nuovo).
Foto del luogo (legacy) supportava una dimensione massima delle foto di 1600 x 1600 pixel. Foto del luogo (nuova) supporta dimensioni fino a 4800 x 4800 pixel.
Per effettuare una richiesta, chiama il nuovo metodo
GMSPlacesClient fetchPhotoWithRequest:callback:
.Passa alla richiesta:
Un'istanza della nuova classe
GMSFetchPhotoRequest
che definisce tutti i parametri della richiesta, incluse le dimensioni massime dell'immagine.Un callback di tipo
GMSPlacePhotoMetadataResultCallback
per gestire la risposta.
Ogni foto è rappresentata da un'istanza
GMSPlacePhotoMetadata
. Per Places SDK for iOS (New), l'istanzaGMSPlacePhotoMetadata
contiene un nuovo campoauthorAttribution
rappresentato dalla nuova classeGMSPlaceAuthorAttribution
.Se l'istanza
GMSPlacePhotoMetadata
restituita includeattributions
oauthorAttribution
, devi includere queste attribuzioni nella tua applicazione ovunque visualizzi l'immagine. Consulta la documentazione sulle attribuzioni.
Esempio di richiesta
Il seguente metodo di esempio accetta un ID luogo e recupera la prima foto nell'elenco restituito. 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: 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 } }]; }];