遷移至地點相片 (新)

Places SDK for iOS 支援現有的 Place Photo。如果您熟悉現有的地點相片,新版 Place Photo 會進行下列變更:

要求範例

下例會擷取地點 ID,並取得傳回清單中的第一張相片。您在自己的應用程式中建立方法時,可以使用此方法做為範本。

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