LocationComponent

The Location Component provides location awareness to your mobile application. Enabling this component provides a contextual experience to your users by showing an icon representing the users current location. A few different modes are offered to provide the right context to your users at the correct time. NORMAL simply shows the users location on the map represented as a dot. COMPASS mode allows you to display an arrow icon (by default) that points in the direction the device is pointing in. GPS can be used in conjunction with our Navigation SDK to display a larger icon (customized with gpsDrawable) we call the user puck.

This component also offers the ability to set a map camera behavior for tracking the user location. These different CameraModes will track, stop tracking the location based on the mode set with setCameraMode.

To get the component object use getLocationComponent and activate it with activateLocationComponent. Then, manage its visibility with setLocationComponentEnabled. The component will not process location updates right after activation, but only after being enabled.

Using this component requires you to request permission beforehand manually or using PermissionsManager. Either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permissions can be requested for this component to work as expected.

This component offers a default, built-in LocationEngine called com.mapbox.mapboxsdk.location.engine.MapboxFusedLocationEngineImpl. If you'd like to utilize the previously available Google Play Services for more precise location updates, refer to the migration guide of 10.0.0 in the changelog. After a custom engine is passed to the component, or the built-in is initialized, the location updates are going to be requested with the LocationEngineRequest, either a default one, or the one passed during the activation. When using any engine, requesting/removing the location updates is going to be managed internally.

You can also push location updates to the component without any internal engine management. To achieve that, set `useDefaultLocationEngine` in LocationComponentActivationOptions to false. No engine is going to be initialized and you can push location updates with forceLocationUpdate.

For location puck animation purposes, like navigation, we recommend limiting the maximum zoom level of the map for the best user experience.

Location Component doesn't support state saving out-of-the-box.

Constructors

Link copied to clipboard
open fun LocationComponent(@NonNull mapboxMap: MapboxMap, @NonNull transform: Transform, @NonNull developerAnimationListeners: List<MapboxMap.OnDeveloperAnimationListener>)
Internal use.

Functions

Link copied to clipboard
This method initializes the component and needs to be called before any other operations are performed.
Link copied to clipboard
Adds a listener that gets invoked when camera tracking state changes.
Link copied to clipboard
Adds a listener that gets invoked when the user clicks the displayed location.
Link copied to clipboard
Adds a listener that gets invoked when the user long clicks the displayed location.
Link copied to clipboard
Adds the passed listener that gets invoked when user updates have stopped long enough for the last update to be considered stale.
Link copied to clipboard
Adds a listener that gets invoked when render mode changes.
Link copied to clipboard
Apply a new component style with location component options.
open fun applyStyle(@NonNull context: Context, @StyleRes styleRes: Int)
Apply a new component style with a style resource.
Link copied to clipboard
Cancels animation started by tiltWhileTracking.
Link copied to clipboard
Cancels animation started by zoomWhileTracking.
Link copied to clipboard
open fun forceLocationUpdate(@Nullable location: Location)
open fun forceLocationUpdate(@Nullable locations: List<Location>, lookAheadUpdate: Boolean)
Use to either force a location update or to manually control when the user location gets updated.
Link copied to clipboard
open fun getCameraMode(): Int
Provides the current camera mode being used to track the location or compass updates.
Link copied to clipboard
Get the last know location of the location component.
Link copied to clipboard
Returns the current location options being used.
Link copied to clipboard
open fun getRenderMode(): Int
Provides the current render mode being used to show the location and/or compass updates on the map.
Link copied to clipboard
Returns whether the location component is activated.
Link copied to clipboard
Returns whether the plugin is enabled, meaning that location can be displayed and camera modes can be used.
Link copied to clipboard
open fun onDestroy()
Internal use.
Link copied to clipboard
Internal use.
Link copied to clipboard
open fun onStart()
Internal use.
Link copied to clipboard
Internal use.
Link copied to clipboard
open fun onStop()
Internal use.
Link copied to clipboard
Removes a listener that gets invoked when camera tracking state changes.
Link copied to clipboard
Removes the passed listener from the current list of location click listeners.
Link copied to clipboard
Removes the passed listener from the current list of location long click listeners.
Link copied to clipboard
Removes the passed listener from the current list of stale listeners.
Link copied to clipboard
Removes a listener that gets invoked when render mode changes.
Link copied to clipboard
open fun setCameraMode(cameraMode: Int)
open fun setCameraMode(cameraMode: Int, @Nullable transitionListener: OnLocationCameraTransitionListener)
open fun setCameraMode(cameraMode: Int, transitionDuration: Long, @Nullable zoom: Double, @Nullable bearing: Double, @Nullable tilt: Double, @Nullable transitionListener: OnLocationCameraTransitionListener)
Sets the camera mode, which determines how the map camera will track the rendered location.
Link copied to clipboard
@RequiresPermission(anyOf = [])
open fun setLocationComponentEnabled(isEnabled: Boolean)
Manage component's visibility after activation.
Link copied to clipboard
open fun setMaxAnimationFps(maxAnimationFps: Int)
Set max FPS at which location animators can output updates.
Link copied to clipboard
open fun setRenderMode(renderMode: Int)
Sets the render mode, which determines how the location updates will be rendered on the map.
Link copied to clipboard
open fun tiltWhileTracking(tilt: Double)
open fun tiltWhileTracking(tilt: Double, animationDuration: Long)
open fun tiltWhileTracking(tilt: Double, animationDuration: Long, @Nullable callback: MapboxMap.CancelableCallback)
Tilts the camera.
Link copied to clipboard
open fun zoomWhileTracking(zoomLevel: Double)
open fun zoomWhileTracking(zoomLevel: Double, animationDuration: Long)
open fun zoomWhileTracking(zoomLevel: Double, animationDuration: Long, @Nullable callback: MapboxMap.CancelableCallback)
Zooms to the desired zoom level.

Properties

Link copied to clipboard
Link copied to clipboard