장소 아이콘은 다양한 유형의 장소 (예: 커피숍, 도서관, 박물관)를 나타냅니다. 현재 위치 및 장소 세부정보 요청을 사용하여 PNG 형식의 아이콘 URL과 해당 아이콘 배경색을 요청할 수 있습니다.
장소의 아이콘 이미지와 배경 색상을 요청하려면 요청에 다음 필드를 포함하세요.
GMSPlaceFieldIconImageURL
GMSPlaceFieldIconBackgroundColor
다음 예는 현재 장소 또는 장소 세부정보 요청의 아이콘 이미지와 배경 색상을 사용하는 방법을 보여줍니다.
iOS용 Places Swift SDK
// Initialize Places Swift clientletplacesClient=PlacesClient.shared// A hotel in Saigon with an attribution.letplaceID="ChIJV4k8_9UodTERU5KXbkYpSYs"// Specify the place data types to return.letfetchPlaceRequest=FetchPlaceRequest(placeID:placeID,placeProperties:[.displayName,.iconMaskURL,.iconBackgroundColor])Task{switchawaitplacesClient.fetchPlace(with:fetchPlaceRequest){case.success(letplace):// Print displayName using String(describing:)print("The selected place is: \(String(describing:place.displayName))")// We primarily need the iconMaskURL to proceed with image loading.// iconBackgroundColor can be handled even if nil.guardleticonMaskURL=place.iconMaskURLelse{print("Icon mask URL not available for this place. Cannot display icon.")return// Exit if iconMaskURL is missing}print("The icon mask URL is: \(iconMaskURL)")// Print iconBackgroundColor using String(describing:)print("The icon background color is: \(String(describing:place.iconBackgroundColor))")// Asynchronously load the icon imageDispatchQueue.global().async{// The iconMaskURL from the new Places SDK is already a URLguardletimageData=try?Data(contentsOf:iconMaskURL)else{print("Could not download image data from URL: \(iconMaskURL)")return}DispatchQueue.main.async{guardleticonImage=UIImage(data:imageData)else{print("Could not create UIImage from downloaded data.")return}// --- Example of how you might use the icon and background color ---// Ensure you have an imageView outlet connected in your UI// For example:// @IBOutlet weak var myImageViewContainer: UIView!// @IBOutlet weak var myIconImageView: UIImageView!// For this example, we'll create them programmatically:leticonBackgroundView=UIView(frame:CGRect(x:0,y:0,width:50,height:50))// Adjust frame as needed// Directly assign the optional UIColor. If nil, background will be clear.iconBackgroundView.backgroundColor=place.iconBackgroundColorletimageView=UIImageView()// Initialize an empty UIImageViewimageView.frame=iconBackgroundView.bounds// Make icon view same size as backgroundimageView.contentMode=.scaleAspectFit// Adjust content mode as needed// Tint the icon image (mask) to white// The icon from iconMaskURL is intended to be used as a mask.lettemplateImage=iconImage.withRenderingMode(.alwaysTemplate)imageView.image=templateImageimageView.tintColor=UIColor.white// Add the image view on top of the background viewiconBackgroundView.addSubview(imageView)}}}}
Swift
// Icon image URLleturl=URL(string:place.iconImageUrl)DispatchQueue.global().async{guardleturl=url,letimageData=try?Data(contentsOf:url)else{print("Could not get image")return}DispatchQueue.main.async{leticonImage=UIImage(data:iconImageData)// Icon image background colorleticonBackgroundView=UIView(frame:.zero)iconBackgroundView.backgroundColor=place.iconBackgroundColor// Change icon image color to whitelettemplateImage=iconImage.imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)imageView.image=templateImageimageView.tintColor=UIColor.white}}
Objective-C
GMSPlace*place;dispatch_async(dispatch_get_global_queue(0,0),^{// Icon image URLNSData*iconImageData=[[NSDataalloc]initWithContentsOfURL:[NSURLURLWithString:place.iconImageUrl]];if(!iconImageData)return;dispatch_async(dispatch_get_main_queue(),^{UIImage*iconImage=[UIImageimageWithData:iconImageData];// Icon image background colorUIView*iconBackgroundView=[[UIViewalloc]initWithFrame:CGRectZero];[iconBackgroundViewsetBackgroundColor:place.iconBackgroundColor];// Change icon image color to whiteiconImage=[iconImageimageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];[imageViewsetTintColor:[UIColorwhiteColor]];});});
필드
각 장소 아이콘에는 다음과 같은 필드가 포함됩니다.
iconImageUrl는 색상이 지정되지 않은 PNG 아이콘의 기본 URL을 반환합니다.
iconBackgroundColor는 장소 카테고리의 기본 UIExtendedSRGBColorSpace 색상 코드를 반환합니다.
장소 아이콘 및 배경색 요청
다음 표에는 사용 가능한 모든 장소 아이콘이 카테고리별로 나와 있습니다. 기본적으로 이러한 장소 아이콘은 검은 글리프로 표시됩니다. 아이콘 배경 색상은 장소의 카테고리에 따라 결정됩니다.
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003ePlace icons, representing various place types like restaurants and libraries, can be accessed through Place Details and Current Place requests.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve icon URLs in PNG format and their background colors using \u003ccode\u003eGMSPlaceFieldIconImageURL\u003c/code\u003e and \u003ccode\u003eGMSPlaceFieldIconBackgroundColor\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eiconImageUrl\u003c/code\u003e provides the base URL for the icon and \u003ccode\u003eiconBackgroundColor\u003c/code\u003e returns the color code associated with the place's category.\u003c/p\u003e\n"],["\u003cp\u003eIcon URLs are subject to change, therefore ensure using \u003ccode\u003eiconImageUrl\u003c/code\u003e for icon retrieval.\u003c/p\u003e\n"],["\u003cp\u003ePlace icons are categorized and displayed with a black glyph by default, with background colors varying by category (e.g., Food and drink with #FF9E67).\u003c/p\u003e\n"]]],[],null,["# Place Icons\n\nSelect platform: [Android](/maps/documentation/places/android-sdk/icons \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/icons \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/place-icons \"View this page for the JavaScript platform docs.\") [Web Service](/maps/documentation/places/web-service/icons \"View this page for the Web Service platform docs.\")\n\nPlace icons indicate the various types of places (for example coffee shops,\nlibraries, and museums). You can request URLs for icons in PNG format, as well\nas the corresponding icon background color, with\n[Current Place](/maps/documentation/places/ios-sdk/current-place),\nand [Place Details](/maps/documentation/places/ios-sdk/place-details)\nrequests.\n\nTo request an icon image and background color for a place, include the\nfollowing fields in your request:\n\n- `GMSPlaceFieldIconImageURL`\n- `GMSPlaceFieldIconBackgroundColor`\n\nThe following examples demonstrate using the icon image and background color\nfrom a Current Place or Place Details request: \n\n### Places Swift SDK for iOS\n\n```swift\n// Initialize Places Swift client\nlet placesClient = PlacesClient.shared\n \n// A hotel in Saigon with an attribution.\nlet placeID = \"ChIJV4k8_9UodTERU5KXbkYpSYs\"\n\n// Specify the place data types to return.\nlet fetchPlaceRequest = FetchPlaceRequest(\n placeID: placeID,\n placeProperties: [.displayName, .iconMaskURL, .iconBackgroundColor]\n)\n \nTask {\n switch await placesClient.fetchPlace(with: fetchPlaceRequest) {\n case .success(let place):\n // Print displayName using String(describing:)\n print(\"The selected place is: \\(String(describing: place.displayName))\")\n\n // We primarily need the iconMaskURL to proceed with image loading.\n // iconBackgroundColor can be handled even if nil.\n guard let iconMaskURL = place.iconMaskURL else {\n print(\"Icon mask URL not available for this place. Cannot display icon.\")\n return // Exit if iconMaskURL is missing\n }\n\n print(\"The icon mask URL is: \\(iconMaskURL)\")\n // Print iconBackgroundColor using String(describing:)\n print(\"The icon background color is: \\(String(describing: place.iconBackgroundColor))\")\n\n\n // Asynchronously load the icon image\n DispatchQueue.global().async {\n // The iconMaskURL from the new Places SDK is already a URL\n guard let imageData = try? Data(contentsOf: iconMaskURL) else {\n print(\"Could not download image data from URL: \\(iconMaskURL)\")\n return\n }\n\n DispatchQueue.main.async {\n guard let iconImage = UIImage(data: imageData) else {\n print(\"Could not create UIImage from downloaded data.\")\n return\n }\n\n // --- Example of how you might use the icon and background color ---\n // Ensure you have an imageView outlet connected in your UI\n // For example:\n // @IBOutlet weak var myImageViewContainer: UIView!\n // @IBOutlet weak var myIconImageView: UIImageView!\n // For this example, we'll create them programmatically:\n\n let iconBackgroundView = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) // Adjust frame as needed\n // Directly assign the optional UIColor. If nil, background will be clear.\n iconBackgroundView.backgroundColor = place.iconBackgroundColor\n\n let imageView = UIImageView() // Initialize an empty UIImageView\n imageView.frame = iconBackgroundView.bounds // Make icon view same size as background\n imageView.contentMode = .scaleAspectFit // Adjust content mode as needed\n\n // Tint the icon image (mask) to white\n // The icon from iconMaskURL is intended to be used as a mask.\n let templateImage = iconImage.withRenderingMode(.alwaysTemplate)\n imageView.image = templateImage\n imageView.tintColor = UIColor.white\n\n // Add the image view on top of the background view\n iconBackgroundView.addSubview(imageView)\n }\n }\n }\n}\n```\n\n### Swift\n\n```swift\n// Icon image URL\nlet url = URL(string: place.iconImageUrl)\nDispatchQueue.global().async {\n guard let url = url,\n let imageData = try? Data(contentsOf: url) else {\n print(\"Could not get image\")\n return\n }\n DispatchQueue.main.async {\n let iconImage = UIImage(data: iconImageData)\n\n // Icon image background color\n let iconBackgroundView = UIView(frame: .zero)\n iconBackgroundView.backgroundColor = place.iconBackgroundColor\n\n // Change icon image color to white\n let templateImage = iconImage.imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate)\n imageView.image = templateImage\n imageView.tintColor = UIColor.white\n }\n}\n```\n\n### Objective-C\n\n```objective-c\nGMSPlace *place;\n\ndispatch_async(dispatch_get_global_queue(0, 0), ^{\n // Icon image URL\n NSData * iconImageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: place.iconImageUrl]];\n if (!iconImageData)\n return;\n dispatch_async(dispatch_get_main_queue(), ^{\n UIImage *iconImage = [UIImage imageWithData:iconImageData];\n\n // Icon image background color\n UIView *iconBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];\n [iconBackgroundView setBackgroundColor:place.iconBackgroundColor];\n\n // Change icon image color to white\n iconImage = [iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];\n [imageView setTintColor:[UIColor whiteColor]];\n });\n});\n```\n| Icon URLs may change, so be sure to always use `iconImageUrl` to look up the URL for an icon.\n\nFields\n------\n\nEach Place icon contains these fields:\n\n- `iconImageUrl` returns the base URL for a non-colored PNG icon.\n- `iconBackgroundColor` returns the default `UIExtendedSRGBColorSpace` color code for the place's category.\n\nPlace icon and background color requests\n----------------------------------------\n\nThe following tables show all of the available place icons by category. By\ndefault these display with a black glyph. The icon background color\nis dictated by the place's category.\n\n| **Place category: Food and drink** (icon background color #FF9E67) ||||\n|--------------------------------------------------------------------|-----------------------------------------|----------------------|------------------|\n| Bar, Night club | Cafe | Restaurant, Bakery |\n| Books, Clothing, Electronics, Jewelry, Shoes, Shopping center/Mall | Convenience store | Grocery, Supermarket | Pharmacy |\n| ATM | Bank | Gas | Lodging |\n| Post office |\n| Aquarium, Tourist | Golf | Historic | Movie |\n| Museum | Theater |\n| Airport | Bus, rideshare, taxi | Train/Rail |\n| Cemetery | Civic building | Library | Monument |\n| Parking | School (primary, secondary, university) | Worship (Christian) |\n| Worship (Hindu) | Worship (Islam) | Worship (Jain) | Worship (Jewish) |\n| Worship (Sikh) | Generic business |\n| Boating | Camping | Park | Stadium |\n| Zoo |\n| Hospital | Police |"]]