NavigationView

public class NavigationView extends RelativeLayout

A View which displays a map for navigation.

Users of this class must forward all the life cycle methods from the Activity or Fragment containing this view to the corresponding ones in this class. In particular, you must forward on the following methods:

If the NavView is added after its parent Activity or Fragment has been through its creation lifecycle, you must call onCreate(Bundle), onStart() and onResume() manually to properly initialize it. Similarly, if a NavView is detached from its parent Activity or Fragment, you must manually call onPause(), onStop() and onDestroy() to prevent leaks.

Note: You are advised not to add children to this view.

All calls to NavView should be performed on the UI thread.

Nested Class Summary

interface NavigationView.OnNightModeChangedListener Interface for a listener which will be notified when the UI enters or exits "night mode". 
interface NavigationView.OnRecenterButtonClickedListener Interface for a listener which will be notified when the recenter button is clicked. 

Inherited Constant Summary

Inherited Field Summary

Public Constructor Summary

NavigationView(Context context)
NavigationView(Context context, GoogleMapOptions googleMapOptions)
NavigationView(Context context, AttributeSet attrs)
NavigationView(Context context, AttributeSet attrs, GoogleMapOptions googleMapOptions)
NavigationView(Context context, AttributeSet attrs, int defStyleAttr)
NavigationView(Context context, AttributeSet attrs, int defStyleAttr, GoogleMapOptions googleMapOptions)

Public Method Summary

void
addOnNavigationUiChangedListener(OnNavigationUiChangedListener listener)
Adds a listener to the list of listeners which will be notified when navigation UI is enabled or disabled.
void
addOnNightModeChangedListener(NavigationView.OnNightModeChangedListener listener)
Adds a listener to the list of listeners which will be notified when the UI enters or exits night mode.
void
addOnRecenterButtonClickedListener(NavigationView.OnRecenterButtonClickedListener listener)
Adds a listener to the list of listeners which will be notified when the recenter button is clicked.
void
getMapAsync(OnMapReadyCallback mapReadyCallback)
Returns a non-null instance of the GoogleMap, ready to be used.
boolean
isNavigationUiEnabled()
Returns whether navigation UI is enabled.
void
onConfigurationChanged(Configuration config)
void
onCreate(Bundle savedInstanceState)
void
void
void
void
onSaveInstanceState(Bundle outState)
void
void
onStop()
void
onTrimMemory(int level)
void
void
void
void
setCalloutInfoDisplayModeOverride(NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)
Overrides default display mode for navigation callouts.
void
setCalloutInfoFormatOverride(RouteCalloutInfoFormat calloutInfoFormatOverride)
Sets the callout info format mode for route callouts.
void
setCustomControl(View control, CustomControlPosition position)
Sets a custom control view which will appear at the given position in the navigation UI.
void
setEtaCardEnabled(boolean enabled)
Sets whether the ETA card is visible during navigation.
void
setForceNightMode(int nightMode)
Sets the current ForceNightMode.
void
setHeaderEnabled(boolean enabled)
Sets whether the turn-by-turn navigation header is visible during navigation.
void
setNavigationUiEnabled(boolean enableNavigationUi)
Enables or disables navigation UI.
void
setRecenterButtonEnabled(boolean enabled)
Sets whether the re-center button should be shown.
void
setSpeedLimitIconEnabled(boolean enabled)
Specifies whether the speed limit icon is shown.
void
setSpeedometerEnabled(boolean enabled)
Specifies whether the speedometer is shown.
void
setSpeedometerUiOptions(SpeedometerUiOptions speedometerUiOptions)
Sets the speedometer UI configuration SpeedometerUiOptions based on SpeedAlertSeverity.
void
setStylingOptions(StylingOptions stylingOptions)
Sets some styling options for the navigation UI.
void
setTrafficIncidentCardsEnabled(boolean enabled)
Sets whether traffic incident cards should be shown when the user clicks on a traffic incident icon.
void
setTrafficPromptsEnabled(boolean enabled)
Sets whether traffic prompts should be shown.
void
setTripProgressBarEnabled(boolean enabled)
Sets whether the trip progress bar is visible during navigation.
void
showRouteOverview()
Pans and zooms the map to show an overview of the remaining route.

Inherited Method Summary

Public Constructors

public NavigationView (Context context)

Parameters
context

public NavigationView (Context context, GoogleMapOptions googleMapOptions)

Parameters
context
googleMapOptions

public NavigationView (Context context, AttributeSet attrs)

Parameters
context
attrs

public NavigationView (Context context, AttributeSet attrs, GoogleMapOptions googleMapOptions)

Parameters
context
attrs
googleMapOptions

public NavigationView (Context context, AttributeSet attrs, int defStyleAttr)

Parameters
context
attrs
defStyleAttr

public NavigationView (Context context, AttributeSet attrs, int defStyleAttr, GoogleMapOptions googleMapOptions)

Parameters
context
attrs
defStyleAttr
googleMapOptions

Public Methods

public void addOnNavigationUiChangedListener (OnNavigationUiChangedListener listener)

Adds a listener to the list of listeners which will be notified when navigation UI is enabled or disabled.

Navigation UI can be turned on or off via:

This allows monitoring navigation UI changes triggered by different APIs.

Parameters
listener the listener to be added.

public void addOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)

Adds a listener to the list of listeners which will be notified when the UI enters or exits night mode. This method should only be called on the UI thread.

Note: In order to avoid memory leaks, use removeOnNightModeChangedListener(OnNightModeChangedListener) to remove the listener that is no longer required.

Parameters
listener a listener which will be notified when the UI enters or exits night mode.

public void addOnRecenterButtonClickedListener (NavigationView.OnRecenterButtonClickedListener listener)

Adds a listener to the list of listeners which will be notified when the recenter button is clicked. This method should only be called on the UI thread.

Note: In order to avoid memory leaks, use removeOnRecenterButtonClickedListener(OnRecenterButtonClickedListener) to remove the listener that is no longer required.

Parameters
listener a listener which will be notified when the recenter button is clicked

public void getMapAsync (OnMapReadyCallback mapReadyCallback)

Returns a non-null instance of the GoogleMap, ready to be used.

Note that:

  • This method must be called from the main thread.
  • The callback will be executed in the main thread.
  • The GoogleMap object provided by the callback is non-null.

Parameters
mapReadyCallback The callback object that will be triggered when the map is ready to be used.

public boolean isNavigationUiEnabled ()

Returns whether navigation UI is enabled.

Navigation UI can be turned on or off via:

public void onConfigurationChanged (Configuration config)

Parameters
config

public void onCreate (Bundle savedInstanceState)

Parameters
savedInstanceState

public void onDestroy ()

public void onPause ()

public void onResume ()

public void onSaveInstanceState (Bundle outState)

Parameters
outState

public void onStart ()

public void onStop ()

public void onTrimMemory (int level)

Parameters
level

public void removeOnNavigationUiChangedListener (OnNavigationUiChangedListener listener)

Parameters
listener the listener to be removed.

public void removeOnNightModeChangedListener (NavigationView.OnNightModeChangedListener listener)

public void removeOnRecenterButtonClickedListener (NavigationView.OnRecenterButtonClickedListener listener)

public void setCalloutInfoDisplayModeOverride (NavigationCalloutDisplayMode calloutInfoDisplayModeOverride)

Overrides default display mode for navigation callouts. Passing null resets the default display mode.

Parameters
calloutInfoDisplayModeOverride the new desired display mode.

public void setCalloutInfoFormatOverride (RouteCalloutInfoFormat calloutInfoFormatOverride)

Sets the callout info format mode for route callouts. If this method is not called, callouts will follow the behavior as defined by RouteCalloutInfoFormat.DEFAULT.

Parameters
calloutInfoFormatOverride the new desired callout format.

public void setCustomControl (View control, CustomControlPosition position)

Sets a custom control view which will appear at the given position in the navigation UI. If any custom control already exists at the given position it will be replaced. Calling this method with a null control value will remove the custom control at the given position. If the control has already been added at a different position or already has a parent, it will be ignored. This method should only be called on the UI thread.

Parameters
control a view that will be positioned within the navigation UI
position determines where the custom control will be placed in the UI relative to built-in controls.

public void setEtaCardEnabled (boolean enabled)

Sets whether the ETA card is visible during navigation. This method should only be called on the UI thread.

Parameters
enabled

public void setForceNightMode (int nightMode)

Sets the current ForceNightMode.

Parameters
nightMode

public void setHeaderEnabled (boolean enabled)

Sets whether the turn-by-turn navigation header is visible during navigation. This method should only be called on the UI thread.

Parameters
enabled

public void setNavigationUiEnabled (boolean enableNavigationUi)

Enables or disables navigation UI.

When navigation UI is enabled, the view is in a navigation-ready state to focus on providing navigation experience. Navigation oriented features will be available under this mode. For example: the camera follows the user’s location, night mode support, navigation focused tile style, speedometer, high detail map style, etc. In contrast, features that are maps focused and conflict with navigation will be unavailable. For example: indoor, zoom control buttons(use gestures instead), my location button.

When navigation UI is disabled, the view will be in a maps focused state where these navigation focused features will be unavailable and those maps focused features would be available. However, if there is an ongoing guided navigation session, it will continue in the background. Guided navigation must be stopped by calling Navigator.stopGuidance().

Navigation UI will also be enabled when GoogleMap.followMyLocation(int) is called.

This call might be asynchronous. For example, when tries to enable navigation UI but no Navigator has not been created. In this case, navigation UI will be enabled only after an instance of Navigator is created. Uses addOnNavigationUiChangedListener(OnNavigationUiChangedListener) to listen to navigation UI change result.

Parameters
enableNavigationUi whether to enable navigation UI.

public void setRecenterButtonEnabled (boolean enabled)

Sets whether the re-center button should be shown. This method should only be called on the UI thread.

Parameters
enabled

public void setSpeedLimitIconEnabled (boolean enabled)

Specifies whether the speed limit icon is shown. Only call this method on the UI thread. By default, the speed limit icon is not shown.

When enabled, a speed limit icon that indicates the speed limit of the road appears in the bottom start corner during guidance. The icon only appears in locations where reliable speed limit data is available. When speedometer icon is visible, they are attached.

If the recenter button is enabled, the speed limit icon is temporarily hidden when the recenter button is shown.

Note: Drivers must follow all posted signs on the road, and use the speed limit icon only as a reference. The accuracy of speed limit data cannot be guaranteed. You may report inaccuracies in our speed limit data by filing a case in the Google Cloud Support Portal.

Parameters
enabled

public void setSpeedometerEnabled (boolean enabled)

Specifies whether the speedometer is shown. Only call this method on the UI thread. By default, the speedometer is not shown.

When enabled, a speedometer that indicates the vehicle speed appears in the bottom start corner during guidance. When speed limit icon is visible, they are attached, and then speedometer can have different colors for text and background, depending on the speeding severity.

Enabling speedometer also enables the speed limit icon altogether, however you can use setSpeedLimitIconEnabled(boolean) to disable/enable speed the limit icon separately.

When the recenter button is enabled, the speedometer is temporarily hidden when the recenter button displays.

Parameters
enabled

public void setSpeedometerUiOptions (SpeedometerUiOptions speedometerUiOptions)

Sets the speedometer UI configuration SpeedometerUiOptions based on SpeedAlertSeverity. Only call this method on the UI thread.

By setting a null SpeedometerUiOptions, you are clearing the previous one if set. When no SpeedometerUiOptions is configured, speedometer UI fallbacks to NavSDK default configurations for speed alerts of different SpeedAlertSeverity:

Parameters
speedometerUiOptions

public void setStylingOptions (StylingOptions stylingOptions)

Sets some styling options for the navigation UI. This method should only be called on the UI thread.

Parameters
stylingOptions

public void setTrafficIncidentCardsEnabled (boolean enabled)

Sets whether traffic incident cards should be shown when the user clicks on a traffic incident icon. This method should only be called on the UI thread.

Note that when guided navigation is running, traffic incident details are shown in prompts. To disable traffic incident details during navigation, setTrafficPromptsEnabled(boolean) should be used instead.

Parameters
enabled

public void setTrafficPromptsEnabled (boolean enabled)

Sets whether traffic prompts should be shown. Traffic prompts periodically appear to update the user on traffic conditions during navigation. This method should only be called on the UI thread.

Parameters
enabled

public void setTripProgressBarEnabled (boolean enabled)

Sets whether the trip progress bar is visible during navigation. This method should only be called on the UI thread.

THIS API IS A BETA RELEASE.
IT IS SUBJECT TO CHANGE AND BACKWARDS COMPATIBILITY IS NOT GUARANTEED

Parameters
enabled

public void showRouteOverview ()

Pans and zooms the map to show an overview of the remaining route. This will temporarily prevent the camera from following the user's position.

The camera can be reset to follow the user using GoogleMap.followMyLocation(int).