نمادهای مکان انواع مختلف مکان ها را نشان می دهند (به عنوان مثال کافی شاپ ها، کتابخانه ها و موزه ها). میتوانید URLها را برای نمادها در قالب PNG و همچنین رنگ پسزمینه نماد مربوطه را با درخواستهای مکان فعلی و جزئیات مکان درخواست کنید.
برای درخواست تصویر نماد و رنگ پس زمینه برای یک مکان، فیلدهای زیر را در درخواست خود قرار دهید:
-
GMSPlaceFieldIconImageURL
-
GMSPlaceFieldIconBackgroundColor
مثالهای زیر استفاده از نماد تصویر و رنگ پسزمینه را از درخواست مکان فعلی یا جزئیات مکان نشان میدهند:
Swift SDK را برای iOS قرار می دهد
// Initialize Places Swift client let placesClient = PlacesClient.shared // A hotel in Saigon with an attribution. let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs" // Specify the place data types to return. let fetchPlaceRequest = FetchPlaceRequest( placeID: placeID, placeProperties: [.displayName, .iconMaskURL, .iconBackgroundColor] ) Task { switch await placesClient.fetchPlace(with: fetchPlaceRequest) { case .success(let place): // 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. guard let iconMaskURL = place.iconMaskURL else { 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 image DispatchQueue.global().async { // The iconMaskURL from the new Places SDK is already a URL guard let imageData = try? Data(contentsOf: iconMaskURL) else { print("Could not download image data from URL: \(iconMaskURL)") return } DispatchQueue.main.async { guard let iconImage = 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: let iconBackgroundView = 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.iconBackgroundColor let imageView = UIImageView() // Initialize an empty UIImageView imageView.frame = iconBackgroundView.bounds // Make icon view same size as background imageView.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. let templateImage = iconImage.withRenderingMode(.alwaysTemplate) imageView.image = templateImage imageView.tintColor = UIColor.white // Add the image view on top of the background view iconBackgroundView.addSubview(imageView) } } } }
سویفت
// Icon image URL let url = URL(string: place.iconImageUrl) DispatchQueue.global().async { guard let url = url, let imageData = try? Data(contentsOf: url) else { print("Could not get image") return } DispatchQueue.main.async { let iconImage = UIImage(data: iconImageData) // Icon image background color let iconBackgroundView = UIView(frame: .zero) iconBackgroundView.backgroundColor = place.iconBackgroundColor // Change icon image color to white let templateImage = iconImage.imageWithRenderingMode(UIImageRenderingModeAlwaysTemplate) imageView.image = templateImage imageView.tintColor = UIColor.white } }
هدف-C
GMSPlace *place; dispatch_async(dispatch_get_global_queue(0, 0), ^{ // Icon image URL NSData * iconImageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: place.iconImageUrl]]; if (!iconImageData) return; dispatch_async(dispatch_get_main_queue(), ^{ UIImage *iconImage = [UIImage imageWithData:iconImageData]; // Icon image background color UIView *iconBackgroundView = [[UIView alloc] initWithFrame:CGRectZero]; [iconBackgroundView setBackgroundColor:place.iconBackgroundColor]; // Change icon image color to white iconImage = [iconImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [imageView setTintColor:[UIColor whiteColor]]; }); });
فیلدها
هر نماد مکان حاوی این فیلدها است:
-
iconImageUrl
URL پایه یک نماد PNG غیر رنگی را برمی گرداند. -
iconBackgroundColor
کد رنگی پیشفرضUIExtendedSRGBColorSpace
را برای دسته مکان برمیگرداند.
نماد مکان و درخواست رنگ پس زمینه
جداول زیر تمام نمادهای مکان موجود را بر اساس دسته بندی نشان می دهد. به طور پیش فرض این نمایش با یک علامت سیاه و سفید. رنگ پسزمینه نماد براساس دستهبندی مکان تعیین میشود.
دسته مکان: غذا و نوشیدنی (رنگ پس زمینه نماد #FF9E67) | |||
---|---|---|---|
نوار، باشگاه شبانه | کافه | رستوران، نانوایی | |
دسته مکان: خرده فروشی (رنگ پس زمینه نماد #4B96F3) | |||
کتاب، پوشاک، لوازم الکترونیکی، جواهرات، کفش، مرکز خرید / مرکز خرید | ![]() خواروبارفروشی کوچک | خواربار فروشی، سوپرمارکت | داروخانه |
دسته مکان: خدمات (رنگ پس زمینه نماد #909CE1) | |||
دستگاه خودپرداز | بانک | گاز | اسکان |
اداره پست | |||
دسته مکان: سرگرمی (رنگ پس زمینه نماد #13B5C7) | |||
آکواریوم، توریستی | گلف | تاریخی | فیلم |
موزه | تئاتر | ||
دسته مکان: حمل و نقل (رنگ پس زمینه نماد #10BDFF) | |||
فرودگاه | اتوبوس، اشتراک سواری، تاکسی | قطار/راه آهن | |
دسته مکان: شهرداری/عمومی/مذهبی (رنگ پس زمینه نماد #7B9EB0) | |||
قبرستان | ساختمان مدنی | کتابخانه | بنای یادبود |
پارکینگ | مدرسه (ابتدایی، راهنمایی، دانشگاه) | عبادت (مسیحی) | |
عبادت (هندو) | عبادت (اسلام) | عبادت (جین) | عبادت (یهودی) |
عبادت (سیک) | تجارت عمومی | ||
دسته مکان: فضای باز (رنگ پس زمینه نماد #4DB546) | |||
قایقرانی | کمپینگ | پارک | استادیوم |
باغ وحش | |||
دسته مکان: اورژانس (رنگ پس زمینه نماد #F88181) | |||
بیمارستان | پلیس |