Das Places SDK for iOS unterstützt das vorhandene Place Photo. Wenn Sie das vorhandene Place Photo bereits kennen, werden in der neuen Version von Place Photo folgende Änderungen vorgenommen:
Verwendet ein neues Preismodell. Preisinformationen für alle APIs finden Sie unter Places SDK for iOS (neu) – Preise.
Das vorhandene Ortsfoto unterstützte eine maximale Fotogröße von 1.600 × 1.600 Pixeln. „Place Photo (New)“ unterstützt Größen von bis zu 4.800 × 4.800 Pixeln.
Um eine Anfrage zu stellen, rufen Sie die neue Methode
GMSPlacesClient lookUpPhotosForPlaceID:
auf und übergeben die Orts-ID als String.Übergeben Sie zur Verarbeitung der Antwort einen Callback vom Typ
GMSPlacePhotoMetadataResultCallback
an die Anfrage.Jedes Foto in der Antwort wird durch eine
GMSPlacePhotoMetadata
-Instanz dargestellt. Beim Places SDK for iOS (New) enthält dieGMSPlacePhotoMetadata
-Instanz ein neuesauthorAttribution
-Feld, das durch die neue Klasse GMSPlaceAuthorAttribution dargestellt wird.Wenn die zurückgegebene
GMSPlacePhotoMetadata
-Instanzattributions
oderauthorAttribution
enthält, müssen Sie diese Attributionen überall dort, wo das Bild zu sehen ist, in Ihre Anwendung einfügen. Weitere Informationen finden Sie in der Dokumentation zu Quellenangaben.
Beispielanfrage
Mit der folgenden Beispielmethode wird eine Orts-ID verwendet, mit der das erste Foto aus der zurückgegebenen Liste abgerufen wird. Sie können diese Methode als Vorlage für die Methode verwenden, die Sie in Ihrer eigenen Anwendung erstellen.
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) } }]; }];