Ikony miejsc wskazują różne typy miejsc (np. kawiarnie, biblioteki i muzea). Możesz poprosić o adresy URL ikon w formacie PNG oraz o odpowiednie kolory tła ikony w ramach żądań bieżącego miejsca i szczegółów miejsca.
Aby poprosić o obraz ikony i kolor tła miejsca, dodaj w prośbie te pola:
GMSPlaceFieldIconImageURL
GMSPlaceFieldIconBackgroundColor
W tych przykładach pokazano użycie obrazu ikony i koloru tła z żądania dotyczącego bieżącej lokalizacji lub szczegółów miejsca:
Pakiet SDK Miejsc Swift na iOS
// 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]];});});
iconBackgroundColor zwraca domyślny UIExtendedSRGBColorSpacekod koloru dla kategorii miejsca.
Prośby o kolor ikony i tła
W tabelach poniżej znajdziesz wszystkie dostępne ikony miejsc pogrupowane według kategorii. Domyślnie są one wyświetlane z czarnym symbolem. Kolor tła ikony jest określony przez kategorię miejsca.
Kategoria miejsca: jedzenie i napoje (kolor tła ikony: #FF9E67)
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-08-27 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 |"]]