When using the following templates, you can add support for users to interact with the maps you draw, such as letting them see different parts of a map by zooming and panning.
| Template | Car App API level support |
|---|---|
NavigationTemplate |
2 |
(deprecated) |
4 |
(deprecated) |
4 |
(deprecated) |
5 (template introduced) |
MapWithContentTemplate |
7 (template introduced) |
Implement interactivity callbacks
The SurfaceCallback interface has several callback methods you can
implement to add interactivity to maps built with the templates in the preceding
section:
| Interaction | Method | Car App API level support |
|---|---|---|
| Tap | onClick |
5 |
| Pinch to zoom | onScale |
2 |
| Single-touch drag | onScroll |
2 |
| Single-touch fling | onFling |
2 |
| Double-tap |
(template host determines scale factor) |
2 |
| Rotary nudge in pan mode |
(template host determines distance factor) |
2 |
Add a map action strip
These templates can have a map action strip for map-related actions such as zooming in and out, recentering, displaying a compass, and other actions you choose to display. The map action strip can contain up to four icon-only buttons that can be refreshed without affecting task depth. The action strip is concealed when in the idle state and reappears in the active state.
To receive map interactivity callbacks, you must add an Action.PAN
button in the map action strip. When the user presses the Pan button, the
host enters pan mode, as described in Understand pan mode.
If your app omits the Action.PAN button in the map action strip, it doesn't
receive user input from the SurfaceCallback methods, and the host closes any
previously activated pan mode.
On a touchscreen, the Pan button isn't displayed.
Understand pan mode
In pan mode, the template host translates user input from non-touch input
devices, such as rotary controllers and touchpads, into the appropriate
SurfaceCallback methods. Respond to the user action to enter or exit pan mode
with the setPanModeListener method in the NavigationTemplate.Builder.
The host can hide other UI components in the template while the user is in pan
mode.