Íconos de lugar

Selecciona la plataforma: Android iOS JavaScript Servicio web

Los íconos de lugar indican los diferentes tipos de lugares (por ejemplo, cafeterías, bibliotecas y museos). Puedes solicitar URLs para íconos en formato PNG, así como el color de fondo del ícono correspondiente, con las solicitudes de Current Place y Place Details.

Para solicitar una imagen de ícono y un color de fondo para un lugar, incluye los siguientes campos en tu solicitud:

  • GMSPlaceFieldIconImageURL
  • GMSPlaceFieldIconBackgroundColor

En los siguientes ejemplos, se muestra el uso de la imagen del ícono y el color de fondo de una solicitud de Place Details o Current Place:

SDK de Places Swift para 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]];
      });
});

Campos

Cada ícono de lugar contiene estos campos:

  • iconImageUrl: Muestra la URL base de un ícono PNG sin color.
  • iconBackgroundColor muestra el código de color UIExtendedSRGBColorSpace predeterminado para la categoría del lugar.

Solicitudes de íconos de lugar y colores de fondo

Las siguientes tablas muestran todos los íconos de lugar disponibles por categoría. De forma predeterminada, estos se muestran con un glifo negro. La categoría del lugar determina el color de fondo del ícono.

Categoría de lugar: Comidas y bebidas
(color de fondo del ícono #FF9E67)
Bar
Bar,
club nocturno
Cafetería
Cafetería
Restaurante
Restaurante, panadería
Categoría de lugar: Venta minorista
(color de fondo del ícono #4B96F3)
Librería
Libros, ropa, artículos electrónicos, artículos de joyería, calzado,
centro comercial
Minimercado
Minimercado
Tienda de alimentos
Tienda de alimentos, supermercado
Farmacia
Farmacia
Categoría de lugar: Servicios
(color de fondo del ícono #909CE1)
Cajero automático
Cajero automático
Banco
Banco
Gasolinera
Gasolinera
Alojamiento
Alojamiento
Oficina de correo
Oficina de correo
Categoría de lugar: Entretenimiento
(color de fondo del ícono #13B5C7)
Acuario, atracción turística
Acuario, atracción turística
Golf
Golf
Lugar histórico
Lugar histórico
Cine
Cine
Museo
Museo
Teatro
Teatro
Categoría de lugar: Transporte
(color de fondo del ícono #10BDFF)
Aeropuerto
Aeropuerto
Autobús
Autobús, transporte compartido, taxi
Tren o tren ligero
Tren o tren ligero
Categoría de lugar: Municipal/genérico/religioso
(color de fondo del ícono #7B9EB0)
Cementerio
Cementerio
Edificio municipal
Edificio municipal
Biblioteca
Biblioteca
Monumento
Monumento
Estacionamiento
Estacionamiento
Institución educativa (primaria, secundaria o universitaria)
Institución educativa (primaria, secundaria o universitaria)
Lugar de culto (cristiano)
Lugar de culto (cristiano)
Lugar de culto (hindú)
Lugar de culto (hindú)
Lugar de culto (islámico)
Lugar de culto (islámico)
Lugar de culto (jainista)
Lugar de culto (jainista)
Lugar de culto (judío)
Lugar de culto (judío)
Lugar de culto (sij)
Lugar de culto (sij)
Empresa genérica
Empresa genérica
Categoría de lugar: Actividades al aire libre
(color de fondo del ícono #4DB546)
Náutica
Náutica
Campamento
Campamento
Parque
Parque
Estadio
Estadio
Zoológico
Zoológico
Categoría de lugar: Emergencia
(color de fondo del ícono #F88181)
Hospital
Hospital
Policía
Policía