# PlaceMarker.Builder

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/PlaceMarker.java+class:androidx.car.app.model.PlaceMarker.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
public final class PlaceMarker.Builder
```

<br />

*** ** * ** ***

A builder of `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#Builder()()` Returns an empty `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder` instance. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/PlaceMarker` | `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#build()()` Constructs the `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker` defined by this builder. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder` | `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#setColor(androidx.car.app.model.CarColor)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarColor color)` Sets the color that should be used for the marker on the map. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder` | `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#setIcon(androidx.car.app.model.CarIcon,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon icon, int iconType)` Sets the icon to display in the marker. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder` | `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#setLabel(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html label)` Sets the text that should be displayed as the marker's content. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public Builder()
```

Returns an empty `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder` instance.

## Public methods

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @NonNull PlaceMarker build()
```

Constructs the `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker` defined by this builder.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the icon is of the type `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker#TYPE_IMAGE()` and a a color is set |

### setColor

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @NonNull PlaceMarker.Builder setColor(@NonNull 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 `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker` is displayed on the map, the pin enclosing the icon or label will be painted using the given color.
- When the `https://developer.android.com/reference/androidx/car/app/model/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 colored and will always use the default color as chosen by the host.

Unless set with this method, the host will use a default color for the marker.

The host may 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 `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker#TYPE_IMAGE()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if the `color` is `null` |

### setIcon

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

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

Sets the icon to display in the marker.

Unless set with this method, the marker will not have an icon.

If a label is specified with `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#setLabel(java.lang.CharSequence)`, the icon will take precedence over it.

#### Icon Sizing Guidance

If the input icon's size exceeds the sizing requirements for the given icon type in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

See `https://developer.android.com/reference/androidx/car/app/model/CarIcon` for more details related to providing icon and image resources that work with different car screen pixel densities.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon icon` | the `https://developer.android.com/reference/androidx/car/app/model/CarIcon` to display inside the marker |
| `int iconType` | one of `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker#TYPE_ICON()` or `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker#TYPE_IMAGE()` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if the `icon` is `null` |

### setLabel

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @NonNull PlaceMarker.Builder setLabel(@NonNull CharSequence label)
```

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

Unless set with this method, the marker will not have a label.

If an icon is specified with `https://developer.android.com/reference/androidx/car/app/model/PlaceMarker.Builder#setIcon(androidx.car.app.model.CarIcon,int)`, the icon will take precedence.

Spans are not supported in the input string and will be ignored.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html label` | 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) |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if the `label` is `null` |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/CarText` |   |