این محصول یا ویژگی در وضعیت Legacy است. برای اطلاعات بیشتر درباره وضعیت Legacy به محصولات و ویژگی های Legacy مراجعه کنید. برای مهاجرت به Places API برای iOS (جدید)، به راهنمای مهاجرت مراجعه کنید.
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
میتوانید از Places SDK برای iOS برای درخواست عکسهای مکان برای نمایش در برنامهتان استفاده کنید. عکسهای ارائهشده توسط سرویس عکسها از منابع مختلفی از جمله صاحبان مشاغل و عکسهای ارائهشده توسط کاربر میآیند. برای بازیابی عکس برای یک مکان، باید مراحل زیر را انجام دهید:
روش مثال زیر یک شناسه مکان می گیرد و اولین عکس را در لیست برگشتی می گیرد. می توانید از این روش به عنوان الگوی روشی که در برنامه خود ایجاد می کنید استفاده کنید.
سویفت
// Specify the place data types to return (in this case, just photos).letfields:GMSPlaceField=GMSPlaceField(rawValue:UInt(GMSPlaceField.photos.rawValue))!placesClient?.fetchPlace(fromPlaceID:"INSERT_PLACE_ID_HERE",placeFields:fields,sessionToken:nil,callback:{(place:GMSPlace?,error:Error?)inifleterror=error{print("An error occurred: \(error.localizedDescription)")return}ifletplace=place{// Get the metadata for the first photo in the place photo metadata list.letphotoMetadata:GMSPlacePhotoMetadata=place.photos![0]// Call loadPlacePhoto to display the bitmap and attribution.self.placesClient?.loadPlacePhoto(photoMetadata,callback:{(photo,error)->Voidinifleterror=error{// TODO: Handle the error.print("Error loading photo metadata: \(error.localizedDescription)")return}else{// Display the first image and its attributions.self.imageView?.image=photo;self.lblText?.attributedText=photoMetadata.attributions;}})}})
هدف-C
// Specify the place data types to return (in this case, just photos).GMSPlaceFieldfields=(GMSPlaceFieldPhotos);NSString*placeId=@"INSERT_PLACE_ID_HERE";[_placesClientfetchPlaceFromPlaceID:placeIdplaceFields:fieldssessionToken:nilcallback:^(GMSPlace*_Nullableplace,NSError*_Nullableerror){if(error!=nil){NSLog(@"An error occurred %@",[errorlocalizedDescription]);return;}if(place!=nil){GMSPlacePhotoMetadata*photoMetadata=[placephotos][0];[self->_placesClientloadPlacePhoto:photoMetadatacallback:^(UIImage*_Nullablephoto,NSError*_Nullableerror){if(error!=nil){NSLog(@"Error loading photo metadata: %@",[errorlocalizedDescription]);return;}else{// Display the first image and its attributions.self->imageView.image=photo;self->lblText.attributedText=photoMetadata.attributions;}}];}}];
برای پیکربندی رفتار حافظه پنهان، میتوانید حافظه پنهان URL مشترک را با استفاده از [NSURLCache setSharedURLCache:] در application:didFinishLaunchingWithOptions:
اگر نمیخواهید برنامه شما یک NSURLCache را با Places SDK برای iOS به اشتراک بگذارد، میتوانید یک NSURLCache جدید ایجاد کنید و از آن منحصراً در برنامه خود استفاده کنید بدون اینکه آن را به عنوان حافظه پنهان مشترک تنظیم کنید.
اسناد
در بیشتر موارد، عکسهای مکان را میتوان بدون ذکر منبع استفاده کرد، یا به عنوان بخشی از تصویر، اسناد مورد نیاز را درج میکند. با این حال، اگر نمونه GMSPlacePhotoMetadata برگشتی شامل یک انتساب باشد، باید هرجا که تصویر را نمایش میدهید، انتساب اضافی را در برنامه خود قرار دهید. توجه داشته باشید که پیوندهای موجود در منبع باید قابل لمس باشند. اسناد مربوط به اسناد را ببینید.
محدودیت های استفاده
بازیابی یک تصویر یک واحد سهمیه هزینه دارد. هیچ محدودیتی برای بازیابی متادیتای عکس وجود ندارد. درباره استفاده و صورتحساب بیشتر بخوانید.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Place Photos\n\nYou can use the Places SDK for iOS to request place photos to display in\nyour application. Photos returned by the photos service come from a variety of\nsources, including business owners and user-contributed photos. To retrieve\nphotos for a place, you must take the following steps:\n\n1. Call [`[GMSPlacesClient\n fetchPlaceFromPlaceId]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-fetchplacefromplaceid:placefields:sessiontoken:callback:), passing a string with a place ID and a callback. This will call the callback with a [`GMSPlacePhotoMetadataList`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadataList) object.\n2. On the [`GMSPlacePhotoMetadataList`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadataList) object access the [`results`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadataList#results) property and select the photos to load from the array.\n3. For each [`GMSPlacePhotoMetadata`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacePhotoMetadata) to load from this list call [`[GMSPlacesClient\n loadPlacePhoto:callback:]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-loadplacephoto:callback:) or [`[GMSPlacesClient\n loadPlacePhoto:constrainedToSize:scale:callback:]`](/maps/documentation/places/ios-sdk/reference/objc/Classes/GMSPlacesClient#-loadplacephoto:constrainedtosize:scale:callback:). These will call the callback with a usable UIImage. Photos can have a maximum width or height of 1600 pixels.\n\n| **Note:** Whenever you display a place photo, 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### Swift\n\n```swift\n// Specify the place data types to return (in this case, just photos).\nlet fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.photos.rawValue))!\n\nplacesClient?.fetchPlace(fromPlaceID: \"INSERT_PLACE_ID_HERE\",\n placeFields: fields,\n sessionToken: nil, callback: {\n (place: GMSPlace?, error: Error?) in\n if let error = error {\n print(\"An error occurred: \\(error.localizedDescription)\")\n return\n }\n if let place = place {\n // Get the metadata for the first photo in the place photo metadata list.\n let photoMetadata: GMSPlacePhotoMetadata = place.photos![0]\n\n // Call loadPlacePhoto to display the bitmap and attribution.\n self.placesClient?.loadPlacePhoto(photoMetadata, callback: { (photo, error) -\u003e Void in\n if let error = error {\n // TODO: Handle the error.\n print(\"Error loading photo metadata: \\(error.localizedDescription)\")\n return\n } else {\n // Display the first image and its attributions.\n self.imageView?.image = photo;\n self.lblText?.attributedText = photoMetadata.attributions;\n }\n })\n }\n})\n```\n\n### Objective-C\n\n```objective-c\n// Specify the place data types to return (in this case, just photos).\nGMSPlaceField fields = (GMSPlaceFieldPhotos);\n\nNSString *placeId = @\"INSERT_PLACE_ID_HERE\";\n\n[_placesClient fetchPlaceFromPlaceID:placeId placeFields:fields sessionToken:nil callback:^(GMSPlace * _Nullable place, NSError * _Nullable error) {\n if (error != nil) {\n NSLog(@\"An error occurred %@\", [error localizedDescription]);\n return;\n }\n if (place != nil) {\n GMSPlacePhotoMetadata *photoMetadata = [place photos][0];\n [self-\u003e_placesClient loadPlacePhoto:photoMetadata callback:^(UIImage * _Nullable photo, NSError * _Nullable error) {\n if (error != nil) {\n NSLog(@\"Error loading photo metadata: %@\", [error localizedDescription]);\n return;\n } else {\n // Display the first image and its attributions.\n self-\u003eimageView.image = photo;\n self-\u003elblText.attributedText = photoMetadata.attributions;\n }\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 don't 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 an attribution, you must include the additional attribution\nin your application wherever you display the image. Note that links in the\nattribution must be tappable. See the documentation on [attributions](/maps/documentation/places/ios-sdk/attributions).\n\nUsage limits\n------------\n\nRetrieving an image costs one unit of quota; there are no usage limits for\nretrieving photo metadata. Read more about\n[usage and billing](/maps/documentation/places/ios-sdk/usage-and-billing)."]]