يمكنك استخدام "حزمة تطوير برامج الأماكن لنظام التشغيل iOS" (الجديدة) لطلب صور الأماكن وعرضها في تطبيقك. يتم الحصول على الصور التي تعرضها خدمة "صور Google" من مجموعة متنوعة من المصادر، بما في ذلك مالكو الأنشطة التجارية والصور التي يساهم بها المستخدمون.
الصور هي صور نقطية يتم تمثيلها بواسطة كائن UIImage.
يبلغ الحد الأقصى لحجم صورة نقطية 4800 × 4800 بكسل.
من عنصر GMSPlacePhotoMetadataList في دالة معاودة الاتصال، تحتوي السمة results الخاصة بالمصفوفة على الصور، حيث يتم تمثيل كل صورة بواسطة عنصر GMSPlacePhotoMetadata.
استخدِم العنصر GMSPlacePhotoMetadata لإنشاء GMSFetchPhotoRequest، بما في ذلك الحد الأقصى لحجم الصورة المطلوبة.
هناك طريقة أخرى لطلب صور لمكان معيّن، وهي تقديم طلب تفاصيل المكان (جديد)، مع تضمين GMSPlacePropertyPhotos في قائمة الحقول. تتمثّل ميزة إجراء طلب
Place Details في أنّ عنصر الاستجابة
GMSPlace
يمكن أن يحتوي على الصور وأي حقول بيانات أخرى تريدها
للمكان.
نموذج التعليمات البرمجية
يأخذ مثال الطريقة التالي معرّف مكان ويحصل على الصورة الأولى في القائمة التي تم إرجاعها. يمكنك استخدام هذه الطريقة كنموذج للطريقة التي ستنشئها في تطبيقك.
Places Swift SDK
// 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}}];}];
لضبط سلوك التخزين المؤقت، يمكنك تغيير ذاكرة التخزين المؤقت لعنوان URL المشترَك باستخدام
[NSURLCache setSharedURLCache:]
في طريقة application:didFinishLaunchingWithOptions:
لمندوب التطبيق.
إذا كنت لا تريد أن يشارك تطبيقك NSURLCache مع حزمة تطوير البرامج (SDK) الخاصة بـ "أماكن Google" لنظام التشغيل iOS، يمكنك إنشاء NSURLCache جديد واستخدامه حصريًا داخل تطبيقك بدون ضبطه كذاكرة التخزين المؤقت المشتركة.
عمليات تحديد المصدر
في معظم الحالات، يمكن استخدام صور الأماكن بدون الإشارة إلى المصدر، أو سيتم تضمين الإشارة المطلوبة إلى المصدر كجزء من الصورة. ومع ذلك، إذا كان العنصر الذي تم عرضه
GMSPlacePhotoMetadata
يتضمّن أي
attributions
أو
authorAttribution،
عليك تضمين هذه الإشارات في تطبيقك في أي مكان تعرض فيه الصورة. يمكنك الاطّلاع على المستندات حول المصادر.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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)."]]