User location

SDKs covered:
Navigation SDK
Navigation UI SDK

Navigation applications often use the user's current location as the origin when requesting a route. With the Navigation SDK, this is done using the LocationEngine class. By default, the Navigation SDK will use the best location engine available and display the user's location with the default styles described below. This guide walks through how to customize both the user location icon and the location engine.

help
More on LocationEngine

For more details on how LocationEngine works, see the LocationEngine documentation.

The logic for getting user location lives in the core Navigation SDK. If you are using the Navigation UI SDK, that data will be styled and displayed in a UI component. Read about default styles for the Navigation UI and where to find more information on customizing the style below.

User location in map view

By default, the style of the user location dot that is added to the map is inherited from the default in the Mapbox Maps SDK for Android. This is a blue dot with a white stroke and a small blue triangle that shows the direction the device is facing.

You can read more about custom styling options for the user location dot in the Maps SDK documentation.

User location along route progress

There is a different icon used to show the user's location while the user is progressing along the route. By default, the user location icon during navigation is a white circle containing a blue arrow.

You can read more about custom styling options for the user location GPS icon in the Maps SDK documentation.

NavigationMapboxMap map = navigationView.retrieveNavigationMapboxMap();
map.updateLocationLayerRenderMode(RenderMode.NORMAL);

Customize location engine

You can set up an instance of a LocationEngine and pass it to the MapboxNavigation object. This is not required — the SDK will create a default LocationEngine with LocationEngineProvider#getBestLocationEngine if an engine is not passed before navigation is started.

LocationEngine locationEngine = LocationEngineProvider.getBestLocationEngine(context);
navigation.setLocationEngine(locationEngine);

You can also pass a LocationEngineRequest to MapboxNavigation, specifying parameters such as update frequency or preferred accuracy. This is also not required — the SDK will create a default LocationEngineRequest with parameters suitable for navigation if a request is not passed before navigation is started.

LocationEngineRequest locationEngineRequest = new LocationEngineRequest.Builder(DEFAULT_INTERVAL_IN_MILLISECONDS)
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
.setMaxWaitTime(DEFAULT_MAX_WAIT_TIME)
.build();
navigation.setLocationEngineRequest(locationEngineRequest);