A template that provides a navigation bar and map buttons allowing users to interact with your app.


class CPMapTemplate : CPTemplate


After the system calls your app delegate’s application(_:didConnectCarInterfaceController:to:) method, create a CPMapTemplate object, and set it as the root template for your interface controller by calling setRootTemplate(_:animated:).

The map template appears as an overlay on top of the base view. The template is the control layer, providing a navigation bar and map buttons that users interact with through the CarPlay screen.

When the user begins to interact with your app through the CarPlay screen, the system displays the navigation bar, hiding it after a brief period of inactivity. You can change this behavior by setting the automaticallyHidesNavigationBar and hidesButtonsWithNavigationBar properties.

The navigation bar includes up to two leading and two trailing buttons. You can change the buttons, including their title and icon image, by setting the leadingNavigationBarButtons and trailingNavigationBarButtons properties on your template.

Also, you can display additional map buttons by providing an array of CPMapButton objects to mapButtons. Use these buttons to provide users access to actions such as entering panning mode or zooming in and out on the map.


Configuring Map Templates

var automaticallyHidesNavigationBar: Bool

A Boolean value that indicates whether the template should automatically hide the navigation bar.

var hidesButtonsWithNavigationBar: Bool

A Boolean value that tells the system to hide the map buttons when hiding the navigation bar.

var guidanceBackgroundColor: UIColor

The background color the map template uses when displaying guidance.

Handling Map Template Events

var mapDelegate: CPMapTemplateDelegate?

The object that serves as the delegate of the map template.

protocol CPMapTemplateDelegate

The protocol an object implements to handle events from a map template.

Managing Map Buttons

var mapButtons: [CPMapButton]

An array of map buttons displayed on the trailing bottom corner of the map template.

class CPMapButton

A button representing an action that a map template displays on the CarPlay screen.

Displaying Trip Previews

func showTripPreviews([CPTrip], textConfiguration: CPTripPreviewTextConfiguration?)

Displays the preview for one or more trips and allows route selection.

func hideTripPreviews()

Hides the display of trip previews.

class CPTripPreviewTextConfiguration

A configuration object that lets you change the button titles displayed on a trip preview.

Navigating a Trip

Providing Trip Estimates

func updateEstimates(CPTravelEstimates, for: CPTrip)

Updates travel estimates, such as arrival time and remaining time and distance for a trip.

func update(CPTravelEstimates, for: CPTrip, with: CPTimeRemainingColor)

Updates travel estimates, such as arrival time and remaining time and distance for a trip, with the specified time-remaining color.

enum CPTimeRemainingColor

The color the system uses when displaying the time remaining for a trip.

var tripEstimateStyle: CPTripEstimateStyle

The style that the map template uses when displaying trip estimates during active nagivation.

enum CPTripEstimateStyle

The set of display styles for trip estimates.

Displaying a Navigation Alert

func present(navigationAlert: CPNavigationAlert, animated: Bool)

Displays a navigation alert on the map template.

func dismissNavigationAlert(animated: Bool, completion: (Bool) -> Void)

Tells the map template to dismiss the visable navigation alert.

class CPNavigationAlert

An alert that displays map- or navigation-related information to the user.

Panning the Map

func showPanningInterface(animated: Bool)

Shows the panning interface over the map.

func dismissPanningInterface(animated: Bool)

Dismisses the panning interface.

var isPanningInterfaceVisible: Bool

A Boolean value that indicates whether the map template is displaying the panning interface.


Inherits From

See Also

User Interface Basics

class CPInterfaceController

A controller that manages the templates that provide the user interface for your app on the CarPlay screen.

class CPListTemplate

A template that displays a hierarchical list of items.

class CPGridTemplate

A template that displays a grid of items.

class CPTemplate

An abstract base class for interface templates.

class CPImageSet

Light and dark representations of an image.