Os ícones de lugar indicam os vários tipos de local (por exemplo, cafés, bibliotecas e museus). Você pode solicitar URLs para ícones no formato PNG, além
da cor do plano de fundo do ícone correspondente, com solicitações de
Local atual e
Detalhes do lugar.
Para solicitar uma imagem de ícone e uma cor de plano de fundo para um lugar, inclua os seguintes campos na solicitação:
GMSPlaceFieldIconImageURL
GMSPlaceFieldIconBackgroundColor
Os exemplos a seguir demonstram o uso da imagem do ícone e da cor de segundo plano de uma solicitação de "Current Place" ou "Place Details":
SDK do Places Swift para 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]];});});
Campos
Cada ícone de lugar contém estes campos:
iconImageUrl retorna o URL de base para um ícone PNG sem cor.
iconBackgroundColor retorna o código de cor UIExtendedSRGBColorSpace
padrão para a categoria do lugar.
Solicitações de ícone de lugar e cor do plano de fundo
As tabelas a seguir mostram todos os ícones de lugar disponíveis por categoria. Por padrão, elas aparecem com um glifo preto. A cor de fundo do ícone é definida pela categoria do lugar.
Categoria do lugar: alimentos e bebidas (cor #FF9E67 do plano de fundo do ícone)
Bar, Clube noturno
Café
Restaurante, padaria
Categoria do lugar: varejo (cor #4B96F3 do plano de fundo do ícone)
Livros, roupas, eletrônicos, joias, sapatos, Shopping Center
Loja de conveniência
Mercearia, supermercado
Farmácia
Categoria do lugar: serviços (cor #909CE1 do plano de fundo do ícone)
Caixa eletrônico
Banco
Postos de gasolina
Hospedagem
Correio
Categoria do lugar: entretenimento (cor #13B5C7 do plano de fundo do ícone)
Aquário, turista
Golfe
Histórico
Filme
Museu
Teatro
Categoria do lugar: transporte (cor #10BDFF do plano de fundo do ícone)
Aeroporto
Ônibus, serviço de transporte por aplicativo, táxi
Trem/Via férrea
Categoria do lugar: municipal/genérico/religioso (cor #7B9EB0 do plano de fundo do ícone)
Cemitério
Construção civil
Biblioteca
Monumento
Estacionamento
Escola (primária, secundária, universidade)
Igreja (cristã)
Templo (hindu)
Mesquita (islâmica)
Templo (jainista)
Templo (judeu)
Templo (siquista)
Empresa genérica
Categoria do lugar: ao ar livre (cor #4DB546 do plano de fundo do ícone)
Barco
Acampamento
Parque
Estádio
Zoológico
Categoria do lugar: emergência (cor #F88181 do plano de fundo do ícone)
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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 |"]]