さまざまな種類の場所(コーヒー ショップ、図書館、美術館など)を表す場所アイコンがあります。現在の場所リクエストと Place Details リクエストを使用して、PNG 形式のアイコンの URL と、対応するアイコンの背景色をリクエストできます。
場所のアイコン画像と背景色をリクエストするには、リクエストに次のフィールドを含めます。
GMSPlaceFieldIconImageURL
GMSPlaceFieldIconBackgroundColor
次の例は、現在の場所または Place Details リクエストのアイコン画像と背景色を使用する方法を示しています。
iOS 向け Places Swift SDK
// 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) } } } }
Swift
// 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 } }
Objective-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
は、色付きでない PNG アイコンのベース URL を返します。iconBackgroundColor
は、場所のカテゴリのデフォルトのUIExtendedSRGBColorSpace
色コードを返します。
場所のアイコンと背景色のリクエスト
次の表には、利用可能な場所アイコンがカテゴリ別にまとめられています。デフォルトでは、これらのアイコンは黒いグリフで表示されます。アイコンの背景色は、場所のカテゴリによって指定されます。
場所のカテゴリ: 食品、飲料 (アイコンの背景色 #FF9E67) |
|||
---|---|---|---|
バー、 ナイトクラブ |
カフェ |
レストラン、ベーカリー |
|
場所のカテゴリ: 小売 (アイコンの背景色 #4B96F3) |
|||
書籍、衣料品、電化製品、ジュエリー、靴、 ショッピング センター / モール |
![]() コンビニエンス ストア |
食料品店、スーパーマーケット |
薬局 |
場所のカテゴリ: サービス (アイコンの背景色 #909CE1) |
|||
ATM |
銀行 |
ガソリン |
宿泊施設 |
郵便局 |
|||
場所のカテゴリ: エンターテインメント (アイコンの背景色 #13B5C7) |
|||
水族館、観光 |
ゴルフ |
歴史にゆかりがある場所 |
映画 |
博物館 |
劇場 |
||
場所のカテゴリ: 交通機関 (アイコンの背景色 #10BDFF) |
|||
空港 |
バス、配車サービス、タクシー |
電車 / 鉄道 |
|
場所のカテゴリ: 公営 / 一般 / 宗教施設 (アイコンの背景色 #7B9EB0) |
|||
墓地 |
公民館 |
図書館 |
記念碑 |
駐車場 |
学校(小学校、中学校、高校、大学) |
礼拝(キリスト教) |
|
礼拝(ヒンズー教) |
礼拝(イスラム教) |
礼拝(ジャイナ教) |
礼拝(ユダヤ教) |
礼拝(シーク教) |
一般的なお店やサービス |
||
場所のカテゴリ: アウトドア (アイコンの背景色 #4DB546) |
|||
ボート |
キャンプ |
公園 |
スタジアム |
動物園 |
|||
場所のカテゴリ: 緊急対応 (アイコンの背景色 #F88181) |
|||
病院 |
警察 |