Android 12 Developer Preview is here! Try it out, and give us your feedback!

PlaceMarker.Builder

public static class PlaceMarker.Builder
extends Object

java.lang.Object
   ↳ com.google.android.libraries.car.app.model.PlaceMarker.Builder


A builder of PlaceMarker.

Summary

Public methods

PlaceMarker build()

Constructs the PlaceMarker defined by this builder.

PlaceMarker.Builder setColor(CarColor color)

Sets the color that should be used for the marker on the map.

PlaceMarker.Builder setIcon(CarIcon icon, int iconType)

Sets the icon to display in the marker, or null to not display one.

PlaceMarker.Builder setLabel(CharSequence label)

Sets the text that should be displayed as the marker's content.

Inherited methods

Public methods

build

public PlaceMarker build ()

Constructs the PlaceMarker defined by this builder.

Returns
PlaceMarker

Throws
IllegalStateException if the icon is of the type PlaceMarker.TYPE_IMAGE and a a color is set.

setColor

public PlaceMarker.Builder setColor (CarColor color)

Sets the color that should be used for the marker on the map.

This color is applied in the following cases:

  • When the PlaceMarker is displayed on the map, the pin enclosing the icon or label will be painted using the given color.
  • When the PlaceMarker is displayed on the list, the color will be applied if the content is a label. A label rendered inside a map's pin cannot be color and will always use the default color as chosen by the host.

When this is set to null, the host will use a default color. The host may also ignore this color and use the default instead if the color does not pass the contrast requirements.

A color cannot be set if the marker's icon type is of PlaceMarker.TYPE_IMAGE.

Parameters
color CarColor

Returns
PlaceMarker.Builder

setIcon

public PlaceMarker.Builder setIcon (CarIcon icon, 
                int iconType)

Sets the icon to display in the marker, or null to not display one.

If a label is specified with setLabel(CharSequence), the icon will take precedence over it.

Icon Sizing Guidance

If the size of the provided icon exceeds the size requirements described above in either one of the dimensions, it will be scaled down and centered inside the bounding box while preserving the aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters
icon CarIcon: the CarIcon to display inside the marker.

iconType int: one of PlaceMarker.TYPE_ICON or PlaceMarker.TYPE_IMAGE.

Returns
PlaceMarker.Builder

setLabel

public PlaceMarker.Builder setLabel (CharSequence label)

Sets the text that should be displayed as the marker's content.

If an icon is specified with setIcon(CarIcon, int), the icon will take precedence.

Parameters
label CharSequence: the text to display inside of the marker. The string must have a maximum size of 3 characters. Set to null to let the host choose a labelling scheme (for example, using a sequence of numbers).

Returns
PlaceMarker.Builder