Développeurs de l'Espace économique européen (EEE)
Vous pouvez utiliser le SDK Places pour iOS (nouveau) afin de demander des photos de lieux à afficher dans votre application. Les photos renvoyées par le service Photos proviennent de diverses sources, y compris des propriétaires d'établissement et des photos fournies par les utilisateurs.
Les photos sont des images bitmap représentées par un objet UIImage.
La taille maximale d'une image bitmap est de 4 800 x 4 800 pixels.
Demander une image
Vous pouvez demander jusqu'à 10 photos pour un lieu :
À partir de l'objet GMSPlacePhotoMetadataList du rappel, la propriété de tableau results contient les photos, où chaque photo est représentée par un objet GMSPlacePhotoMetadata.
Utilisez l'objet GMSPlacePhotoMetadata pour créer un GMSFetchPhotoRequest, y compris la taille maximale de l'image demandée.
Une autre façon de demander des photos d'un lieu consiste à effectuer une requête Place Details (New), en incluant GMSPlacePropertyPhotos dans la liste des champs. L'avantage d'effectuer un appel Place Details est que l'objet de réponse GMSPlace peut contenir les photos et tous les autres champs de données que vous souhaitez pour le lieu.
Exemple de code
L'exemple de méthode suivant accepte un ID de lieu et obtient la première photo de la liste renvoyée. Vous pouvez utiliser cette méthode comme modèle pour la méthode que vous allez créer dans votre propre application.
SDK Places Swift
// First fetch place details// A hotel in Saigon with an attribution.letplaceID="ChIJV4k8_9UodTERU5KXbkYpSYs"letfetchPlaceRequest=FetchPlaceRequest(placeID:placeID,placeProperties:[.name,.website])varfetchedPlace:PlaceswitchawaitplacesClient.fetchPlace(with:fetchPlaceRequest){case.success(letplace):fetchedPlace=placecase.failure(letplacesError):// Handle error}// Use the place details to fetch a photo's image.guardletphoto=fetchedPlace.photos?.firstelse{// Handle place without photos.}letfetchPhotoRequest=FetchPhotoRequest(photo:photo,maxSize:CGSizeMake(4800,4800))switchawaitplacesClient.fetchPhoto(with:fetchPhotoRequest){case.success(letuiImage):// Handle image.case.failure(letplacesError):// Handle error}
Swift
// A hotel in Saigon with an attribution.letplaceID="ChIJV4k8_9UodTERU5KXbkYpSYs"// Request list of photos for a placeplacesClient.lookUpPhotos(forPlaceID:placeID){(photos,error)inguardletphotoMetadata:GMSPlacePhotoMetadata=photos?.results[0]else{return}// Request individual photos in the response listletfetchPhotoRequest=GMSFetchPhotoRequest(photoMetadata:photoMetadata,maxSize:CGSizeMake(4800,4800))self.client.fetchPhoto(with:fetchPhotoRequest,callback:{(photoImage:UIImage?,error:Error?)inguardletphotoImage,error==nilelse{print("Handle photo error: ")return}print("Display photo Image: ")})}
Objective-C
// A hotel in Saigon with an attribution.NSString*placeID=@"ChIJV4k8_9UodTERU5KXbkYpSYs";[placesClientlookUpPhotosForPlaceID:placeIDcallback:^(GMSPlacePhotoMetadataList*list,NSError*error){GMSPlacePhotoMetadata*photoMetadata=[listresults][0];// Request individual photos in the response listGMSFetchPhotoRequest*fetchPhotoRequest=[[GMSFetchPhotoRequestalloc]initWithPhotoMetadata:photoMetadatamaxSize:CGSizeMake(4800,4800)];[placesClientfetchPhotoWithRequest:fetchPhotoRequestcallback:^(UIImage*_NullablephotoImage,NSError*_Nullableerror){if(error==nil){// Display photo}}];}];
Pour configurer le comportement de mise en cache, vous pouvez modifier le cache d'URL partagé à l'aide de [NSURLCache setSharedURLCache:] dans la méthode application:didFinishLaunchingWithOptions: du délégué de votre application.
Si vous ne souhaitez pas que votre application partage un NSURLCache avec le SDK Places pour iOS, vous pouvez créer un NSURLCache et l'utiliser exclusivement dans votre application sans le définir comme cache partagé.
Attributions
Dans la plupart des cas, les photos de lieux peuvent être utilisées sans attribution, ou contiendront déjà l'attribution. Toutefois, si l'instance GMSPlacePhotoMetadata renvoyée inclut des attributions ou des authorAttribution, vous devez inclure ces attributions dans votre application partout où vous affichez l'image. Consultez la documentation sur les attributions.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (UTC)."],[[["\u003cp\u003eThe Places SDK for iOS allows you to request and display place photos, which are bitmap images up to 4800x4800 pixels, from various sources.\u003c/p\u003e\n"],["\u003cp\u003eYou can request up to 10 photos for a place using \u003ccode\u003eGMSPlacesClient\u003c/code\u003e methods like \u003ccode\u003elookUpPhotosForPlaceID\u003c/code\u003e and \u003ccode\u003efetchPhotoWithRequest\u003c/code\u003e, or by including \u003ccode\u003eGMSPlacePropertyPhotos\u003c/code\u003e in a Place Details request.\u003c/p\u003e\n"],["\u003cp\u003ePhotos retrieved through the SDK are cached by the Foundation URL loading system, and you can configure caching behavior using \u003ccode\u003eNSURLCache\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhile most place photos don't require attribution, if \u003ccode\u003eGMSPlacePhotoMetadata\u003c/code\u003e includes \u003ccode\u003eattributions\u003c/code\u003e or \u003ccode\u003eauthorAttribution\u003c/code\u003e, you must display them with the image.\u003c/p\u003e\n"],["\u003cp\u003eSample code in Swift and Objective-C demonstrates how to fetch and display place photos using the Places SDK for iOS.\u003c/p\u003e\n"]]],["The Places SDK for iOS (New) allows requesting place photos, sourced from business owners and users, for display in apps. To use this feature you first need to Enable the Places API (New). You can request up to ten photos for a place, using `GMSPlacesClient` to look up photos by place ID and receive a `GMSPlacePhotoMetadataList`. Each photo's `GMSPlacePhotoMetadata` is used to create a `GMSFetchPhotoRequest` to retrieve a `UIImage`. Photos can also be requested via Place Details. There are guidelines on attributions that must be followed. Loaded photos are cached using `NSURLCache`.\n"],null,["# Place Photos (New)\n\nSelect platform: [Android](/maps/documentation/places/android-sdk/place-photos \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/place-photos \"View this page for the iOS platform docs.\") [Web Service](/maps/documentation/places/web-service/place-photos \"View this page for the Web Service platform docs.\")\n\n\u003cbr /\u003e\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\n\u003cbr /\u003e\n\n| This feature requires that you enable Places API (New), the next generation of the Places API. For more information, see [Enable APIs](/maps/documentation/places/ios-sdk/cloud-setup#enabling-apis).\n\n\u003cbr /\u003e\n\nYou can use the Places SDK for iOS (New) to request place photos to\ndisplay in your application. Photos returned by the photos service come from a\nvariety of sources, including business owners and user-contributed photos.\n\nPhotos are bitmap images represented by a\n[UIImage](https://developer.apple.com/documentation/uikit/uiimage) object.\nA bitmap image has a maximum size of 4800 by 4800 pixels.\n\nRequest an image\n----------------\n\nYou can request up to 10 photos for a place:\n\n1. Call\n [`[GMSPlacesClient lookUpPhotosForPlaceID]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-lookupphotosforplaceid:callback:),\n passing a place ID and a\n [`GMSPlacePhotoMetadataResultCallback`](/maps/documentation/places/ios-sdk/reference/objc/Type-Definitions#/c:GMSPlacesClient.h@T@GMSPlacePhotoMetadataResultCallback) callback.\n This request calls the `GMSPlacePhotoMetadataResultCallback` callback with a\n [`GMSPlacePhotoMetadataList`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadataList)\n object.\n\n2. From the `GMSPlacePhotoMetadataList` object in the callback, the\n [`results`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadataList#results)\n array property contains the photos, where each photo is represented by a\n [`GMSPlacePhotoMetadata`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadata)\n object.\n\n3. Use the `GMSPlacePhotoMetadata` object to create a\n [`GMSFetchPhotoRequest`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSFetchPhotoRequest),\n including the maximum size of the requested image.\n\n4. For each `GMSPlacePhotoMetadata` object in the array, call\n [`[GMSPlacesClient\n fetchPhotoWithRequest:callback:]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-fetchphotowithrequest:callback:)\n passing the `GMSFetchPhotoRequest` object. This methods calls the\n [`GMSFetchPhotoResultCallback`](/maps/documentation/places/ios-sdk/reference/objc/Type-Definitions#/c:GMSPlacesClient.h@T@GMSFetchPhotoResultCallback)\n callback with a usable bitmap image as a UIImage.\n\nAnother way to request photos for a place is to make a\n[Place Details (New)](/maps/documentation/places/ios-sdk/details-place) request,\nincluding `GMSPlacePropertyPhotos` in the field list. The advantage to making a\nPlace Details call is that the response\n[`GMSPlace`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlace)\nobject can contain the photos and any other data fields that you want for\nthe place.\n| **Note:** Whenever you display a place photo in your app, make sure to follow the attribution guidelines. See [Attributions](#attributions) for more information.\n\nSample code\n-----------\n\nThe following example method takes a place ID and gets the first photo in the\nreturned list. You can use this method as a template for the method you will\ncreate in your own app. \n\n### Places Swift SDK\n\n```swift\n// First fetch place details\n// A hotel in Saigon with an attribution.\nlet placeID = \"ChIJV4k8_9UodTERU5KXbkYpSYs\"\nlet fetchPlaceRequest = FetchPlaceRequest(\n placeID: placeID,\n placeProperties: [ . name, .website ]\n)\nvar fetchedPlace: Place\nswitch await placesClient.fetchPlace(with: fetchPlaceRequest) {\ncase .success(let place):\n fetchedPlace = place\ncase .failure(let placesError):\n // Handle error\n}\n\n// Use the place details to fetch a photo's image.\nguard let photo = fetchedPlace.photos?.first else {\n // Handle place without photos.\n}\nlet fetchPhotoRequest =\n FetchPhotoRequest(photo: photo, maxSize: CGSizeMake(4800, 4800))\nswitch await placesClient.fetchPhoto(with: fetchPhotoRequest) {\ncase .success(let uiImage):\n // Handle image.\ncase .failure(let placesError):\n // Handle error\n}\n```\n\n### Swift\n\n```swift\n// A hotel in Saigon with an attribution.\nlet placeID = \"ChIJV4k8_9UodTERU5KXbkYpSYs\"\n\n// Request list of photos for a place\nplacesClient.lookUpPhotos(forPlaceID: placeID) { (photos, error) in\n\n guard let photoMetadata: GMSPlacePhotoMetadata = photos?.results[0] else {\n return }\n\n // Request individual photos in the response list\n let fetchPhotoRequest = GMSFetchPhotoRequest(photoMetadata: photoMetadata, maxSize: CGSizeMake(4800, 4800))\n self.client.fetchPhoto(with: fetchPhotoRequest, callback: {\n (photoImage: UIImage?, error: Error?) in\n guard let photoImage, error == nil else {\n print(\"Handle photo error: \")\n return }\n print(\"Display photo Image: \")\n }\n )\n}\n```\n\n### Objective-C\n\n```objective-c\n// A hotel in Saigon with an attribution.\nNSString *placeID = @\"ChIJV4k8_9UodTERU5KXbkYpSYs\";\n\n[placesClient lookUpPhotosForPlaceID:placeID callback: ^(GMSPlacePhotoMetadataList *list, NSError *error) {\n GMSPlacePhotoMetadata *photoMetadata = [list results][0];\n\n // Request individual photos in the response list\n GMSFetchPhotoRequest *fetchPhotoRequest = [[GMSFetchPhotoRequest alloc] initWithPhotoMetadata:photoMetadata maxSize:CGSizeMake(4800, 4800)];\n [placesClient fetchPhotoWithRequest:fetchPhotoRequest callback: ^(UIImage *_Nullable photoImage, NSError *_Nullable error) {\n if (error == nil) {\n // Display photo\n }\n }];\n}];\n```\n\nCaching\n-------\n\nPhotos loaded using [`[GMSPlacesClient loadPlacePhoto:callback:]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-loadplacephoto:callback:)\nor [`[GMSPlacesClient loadPlacePhoto:constrainedToSize:scale:callback:]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-loadplacephoto:constrainedtosize:scale:callback:)\nare cached both on disk and in-memory by the [Foundation URL loading system](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html)\nin the shared [`NSURLCache`](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURLCache_Class/index.html).\n\nTo configure the caching behavior you can change the shared URL cache using\n[`[NSURLCache setSharedURLCache:]`](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURLCache_Class/index.html#//apple_ref/occ/clm/NSURLCache/setSharedURLCache:)\nin your application delegate's `application:didFinishLaunchingWithOptions:`\nmethod.\n\nIf you do not want your application to share a `NSURLCache` with the\nPlaces SDK for iOS you can create a new `NSURLCache` and use this\nexclusively within your app without setting it as the shared cache.\n\nAttributions\n------------\n\nIn most cases, place photos can be used without attribution, or will have the\nrequired attribution included as part of the image. However, if the returned\n[`GMSPlacePhotoMetadata`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadata)\ninstance includes any\n[`attributions`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadata#attributions)\nor\n[`authorAttribution`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadata#authorattributions),\nyou must include these attributions in your application wherever you display the\nimage. See the documentation on\n[attributions](/maps/documentation/places/ios-sdk/policies#other_attribution_requirements)."]]