Zu „Place Photos“ (neu) migrieren

Das Places SDK for iOS (Legacy) unterstützt Place Photos (Legacy). Wenn Sie mit Place Photos (Legacy) vertraut sind, beachten Sie, dass Place Photos (New) die folgenden Änderungen mit sich bringt:

  • Verwendet ein neues Preismodell. Preisinformationen für alle APIs finden Sie unter Nutzung und Abrechnung.

  • Place Photos (Legacy) unterstützte eine maximale Fotogröße von 1.600 × 1.600 Pixeln. Place Photos (New) unterstützt Größen bis zu 4.800 × 4.800 Pixel.

  • Rufen Sie die neue Methode GMSPlacesClient fetchPhotoWithRequest:callback: auf, um eine Anfrage zu stellen.

  • Übergeben Sie der Anfrage Folgendes:

  • Jedes Foto wird durch eine GMSPlacePhotoMetadata-Instanz dargestellt. Für das Places SDK for iOS (New) enthält die GMSPlacePhotoMetadata-Instanz ein neues authorAttribution-Feld, das durch die neue GMSPlaceAuthorAttribution-Klasse dargestellt wird.

    Wenn die zurückgegebene GMSPlacePhotoMetadata-Instanz attributions oder authorAttribution enthält, müssen Sie diese Quellenangaben immer dann in Ihre Anwendung einbinden, wenn das Bild zu sehen ist. Weitere Informationen finden Sie in der Dokumentation zu Quellenangaben.

Beispielanfrage

In der folgenden Beispielmethode wird eine Orts-ID verwendet und das erste Foto in der zurückgegebenen Liste abgerufen. Sie können diese Methode als Vorlage für die Methode verwenden, die Sie in Ihrer eigenen App 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: 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
    }
  }];
}];