رموز الأماكن

اختيار النظام الأساسي: Android iOS JavaScript خدمة الويب

تشير رموز الأماكن إلى الأنواع المختلفة من الأماكن (مثل المقاهي والمكتبات والمتاحف). يمكنك طلب عناوين URL للرموز بتنسيق PNG، بالإضافة إلى لون خلفية الرمز المقابل، وذلك من خلال طلبات الموقع الجغرافي الحالي وتفاصيل الموقع الجغرافي.

لطلب صورة رمز ولون خلفية لموقع، أدرِج الحقول التالية في طلبك:

  • GMSPlaceFieldIconImageURL
  • GMSPlaceFieldIconBackgroundColor

توضِّح الأمثلة التالية استخدام صورة الرمز ولون الخلفية من طلب "المكان الحالي" أو طلب "تفاصيل المكان":

حزمة تطوير البرامج (SDK) لأماكن Google باستخدام Swift لأجهزة 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)
        }
      }
  }
}

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 تعرِض عنوان URL الأساسي لرمز PNG غير الملوّن.
  • iconBackgroundColor تعرض رمز اللون التلقائي UIExtendedSRGBColorSpace لفئة المكان.

تقديم طلبات ألوان الرموز والخلفية

تعرض الجداول التالية جميع رموز الأماكن المتاحة حسب الفئة. يتم عرض هذه الرموز تلقائيًا باستخدام رمز رسومي أسود. يعتمد لون خلفية الرمز على فئة المكان.

فئة المكان: الطعام والشراب
(لون خلفية الرمز ‎ #FF9E67)
شريط
حانة،
نادي ليلي
مقهى
مقهى
مطعم
مطعم أو مخبز
فئة المكان: البيع بالتجزئة
(لون خلفية الرمز ‎ #4B96F3)
متجر كتب
كتب، ملابس، إلكترونيات، مجوهرات، أحذية،
مركز تسوّق
متجر صغير
متجر صغير
بقالة
متجر بقالة أو سوبر ماركت
صيدلة
الصيدلية
فئة المكان: خدمات
(لون خلفية الرمز ‎ #909CE1)
ماكينة صراف آلي
ماكينة الصراف الآلي
مصرف
المصرف
غاز
الغاز
أماكن إقامة
الإقامة
مكتب البريد
مكتب بريد
فئة المكان: ترفيه
(لون خلفية الرمز ‎ #13B5C7)
حوض سمك، سياحي
حوض سمك، سياحي
غولف
الغولف
تاريخي
موقع تاريخي
فيلم
فيلم
متحف
متحف
مسرح
المسرح
فئة المكان: وسائل النقل
(لون خلفية الرمز #10BDFF)
مطار
المطار
حافلة
الحافلة ومشاركة الرحلات وسيارات الأجرة
قطار/سكك حديدية
القطار/السكك الحديدية
فئة المكان: بلدية/عامة/دينية
(لون خلفية الرمز #7B9EB0)
مقبرة
مقبرة
مبنى مدني
مبنى مدني
المكتبة
المكتبة
نصب تذكاري
نصب تذكاري
موقف سيارات
موقف السيارات
المدرسة (التعليم الابتدائي والثانوي والجامعي)
المدرسة (التعليم الابتدائي والثانوي والجامعي)
موسيقى شعائر مسيحية
العبادة (مسيحية)
عبادة (هندوسية)
عبادة (هندوسية)
العبادة (الإسلام)
العبادة (الإسلام)
Worship (Jain)
العبادة (اليانية)
موسيقى شعائر يهودية
العبادة (يهودية)
موسيقى شعائر مسيحية (السيخ)
مكان عبادة (السيخ)
نشاط تجاري عام
نشاط تجاري عام
فئة المكان: في الهواء الطلق
(لون خلفية الرمز #4DB546)
ركوب القارب
ركوب القوارب
تخييم
التخييم
متنزّه
متنزه
استاد
الملعب
حديقة حيوانات
حديقة حيوانات
فئة المكان: طوارئ
(لون خلفية الرمز #F88181)
مستشفى
مستشفى
شرطة
الشرطة