Le icone dei luoghi indicano i vari tipi di luoghi (ad esempio caffetterie, biblioteche e musei). Puoi richiedere gli URL delle icone in formato PNG, nonché il colore di sfondo corrispondente, con le richieste Posizione attuale e Dettagli dei luoghi.
Per richiedere un'immagine dell'icona e il colore di sfondo per un luogo, includi i seguenti campi nella richiesta:
GMSPlaceFieldIconImageURL
GMSPlaceFieldIconBackgroundColor
Gli esempi riportati di seguito mostrano l'utilizzo dell'immagine dell'icona e del colore di sfondo
da una richiesta di luogo corrente o di dettagli del luogo:
SDK Places Swift per 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]];});});
Campi
Ogni icona di luogo contiene i seguenti campi:
iconImageUrl restituisce l'URL di base per un'icona PNG non colorata.
iconBackgroundColor restituisce il codice colore UIExtendedSRGBColorSpace predefinito per la categoria del luogo.
Inviare richieste di icone e colori di sfondo
Le tabelle seguenti mostrano tutte le icone dei luoghi disponibili per categoria. Per impostazione predefinita, vengono visualizzati con un glifo nero. Il colore di sfondo dell'icona è determinato dalla categoria del luogo.
Categoria di luogo: Cibo e bevande (colore dello sfondo dell'icona #FF9E67)
Bar, Night club
Bar
Ristorante, panificio
Categoria di luogo: vendita al dettaglio (colore di sfondo dell'icona #4B96F3)
Libri, abbigliamento, elettronica, gioielli, scarpe, centro commerciale/galleria commerciale
Minimarket
Negozio di alimentari, supermercato
Farmacia
Categoria di luogo: Servizi (colore sfondo icona #909CE1)
Bancomat
Banca
Gas
Alloggio
Ufficio postale
Categoria di luogo: Spettacoli (colore di sfondo dell'icona #13B5C7)
Acquario, Turistico
Golf
Storico
Film
Museo
Cinema
Categoria di luogo: Trasporti (colore di sfondo dell'icona #10BDFF)
Aeroporto
Autobus, ridesharing, taxi
Treno/mezzo su rotaie
Categoria di luogo: comunale/generico/religioso (colore dello sfondo dell'icona #7B9EB0)
Cimitero
Edificio pubblico
Raccolta
Monumento
Parcheggio
Scuola (elementare, media, universitaria)
Culto (cristiano)
Adorazione (indù)
Culto (Islam)
Culto (giainista)
Culto (ebraico)
Culto (sikh)
Attività generica
Categoria di luogo: all'aperto (colore di sfondo dell'icona #4DB546)
Nautica
Campeggio
Parcheggia
Stadio
Zoo
Categoria di luogo: Emergenza (colore di sfondo dell'icona #F88181)
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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 |"]]