장소 아이콘

플랫폼 선택: Android iOS JavaScript 웹 서비스

장소 아이콘은 다양한 유형의 장소 (예: 커피숍, 도서관, 박물관)를 나타냅니다. 현재 위치장소 세부정보 요청을 사용하여 PNG 형식의 아이콘 URL과 해당 아이콘 배경색을 요청할 수 있습니다.

장소의 아이콘 이미지와 배경 색상을 요청하려면 요청에 다음 필드를 포함하세요.

  • GMSPlaceFieldIconImageURL
  • GMSPlaceFieldIconBackgroundColor

다음 예는 현재 장소 또는 장소 세부정보 요청의 아이콘 이미지와 배경 색상을 사용하는 방법을 보여줍니다.

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
ATM
은행
은행
주유소
주유소
숙박시설
숙박시설
우체국
우체국
장소 카테고리: 엔터테인먼트
(아이콘 배경색 #13B5C7)
수족관, 관광명소
수족관, 관광명소
골프
골프
유적지
유적지
영화
영화
박물관
박물관
극장
극장
장소 카테고리: 교통
(아이콘 배경색 #10BDFF)
공항
공항
버스
버스, 차량 공유, 택시
기차/철도
기차/철도
장소 카테고리: 시/일반/종교
(아이콘 배경색 #7B9EB0)
묘지
묘지
관청 건물
관청 건물
도서관
도서관
기념비
기념비
주차장
주차장
학교(초등학교, 중고등학교, 대학교)
학교(초등학교, 중고등학교, 대학교)
예배당(기독교)
예배당(기독교)
예배당(힌두교)
예배당(힌두교)
예배당(이슬람교)
예배당(이슬람교)
예배당(자이나교)
예배당(자이나교)
예배당(유대교)
예배당(유대교)
예배당(시크교)
예배당(시크교)
일반 비즈니스
일반 비즈니스
장소 카테고리: 실외
(아이콘 배경색 #4DB546)
보트 타기
보트 타기
캠핑
캠핑
공원
공원
경기장
경기장
동물원
동물원
장소 카테고리: 응급
(아이콘 배경색 #F88181)
병원
병원
경찰서
경찰서