public final class LocationLayerPlugin
extends java.lang.Object
implements android.arch.lifecycle.LifecycleObserver
RenderMode.NORMAL simply shows the users location on the map
represented as a dot. RenderMode.COMPASS mode allows you to display an arrow icon
(by default) that points in the direction the device is pointing in.
RenderMode.GPS can be used in conjunction with our Navigation SDK to
display a larger icon (customized with LocationLayerOptions.gpsDrawable()) we call the user puck.
This plugin 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(int).
Lastly, setLocationLayerEnabled(boolean) can be used
to disable the Location Layer but keep the instance around till the activity is destroyed.
Using this plugin requires you to request permission beforehand manually or using
com.mapbox.android.core.permissions.PermissionsManager. Either
ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permissions can be requested and
this plugin work as expected.
| Constructor and Description |
|---|
LocationLayerPlugin(com.mapbox.mapboxsdk.maps.MapView mapView,
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
com.mapbox.android.core.location.LocationEngine locationEngine)
Construct a LocationLayerPlugin
|
LocationLayerPlugin(com.mapbox.mapboxsdk.maps.MapView mapView,
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
com.mapbox.android.core.location.LocationEngine locationEngine,
int styleRes)
Construct a LocationLayerPlugin
|
LocationLayerPlugin(com.mapbox.mapboxsdk.maps.MapView mapView,
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
com.mapbox.android.core.location.LocationEngine locationEngine,
LocationLayerOptions options)
Construct a LocationLayerPlugin
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCompassListener(CompassListener compassListener)
Add a compass listener to get heading updates every second.
|
void |
addOnCameraTrackingChangedListener(OnCameraTrackingChangedListener listener)
Adds a listener that gets invoked when camera tracking state changes.
|
void |
addOnLocationClickListener(OnLocationLayerClickListener listener)
Adds a listener that gets invoked when the user clicks the location layer.
|
void |
addOnLocationLongClickListener(OnLocationLayerLongClickListener listener)
Adds a listener that gets invoked when the user long clicks the location layer.
|
void |
addOnLocationStaleListener(OnLocationStaleListener listener)
Adds the passed listener that gets invoked when user updates have stopped long enough for the last update
to be considered stale.
|
void |
applyStyle(int styleRes)
Apply a new LocationLayer style with a style resource.
|
void |
applyStyle(LocationLayerOptions options)
Apply a new LocationLayer style with location layer options.
|
void |
forceLocationUpdate(android.location.Location location)
Use to either force a location update or to manually control when the user location gets
updated.
|
int |
getCameraMode()
Provides the current camera mode being used to track
the location or compass updates.
|
android.location.Location |
getLastKnownLocation()
Get the last know location of the location layer plugin.
|
com.mapbox.android.core.location.LocationEngine |
getLocationEngine()
Returns the current
LocationEngine being used for updating the user location layer. |
LocationLayerOptions |
getLocationLayerOptions()
Returns the current location options being used.
|
int |
getRenderMode()
Provides the current render mode being used to show
the location and/or compass updates on the map.
|
void |
onStart()
Required to place inside your activities
onStart method. |
void |
onStop()
Required to place inside your activities
onStop method. |
void |
removeCompassListener(CompassListener compassListener)
Remove a compass listener.
|
void |
removeOnCameraTrackingChangedListener(OnCameraTrackingChangedListener listener)
Removes a listener that gets invoked when camera tracking state changes.
|
void |
removeOnLocationClickListener(OnLocationLayerClickListener listener)
Removes the passed listener from the current list of location click listeners.
|
void |
removeOnLocationLongClickListener(OnLocationLayerLongClickListener listener)
Removes the passed listener from the current list of location long click listeners.
|
void |
removeOnLocationStaleListener(OnLocationStaleListener listener)
Removes the passed listener from the current list of stale listeners.
|
void |
setCameraMode(int cameraMode)
Sets the camera mode, which determines how the map camera will track the rendered location.
|
void |
setLocationEngine(com.mapbox.android.core.location.LocationEngine locationEngine)
Set the location engine to update the current user location.
|
void |
setLocationLayerEnabled(boolean isEnabled)
This method will show or hide the location icon and enable or disable the camera
tracking the location.
|
void |
setRenderMode(int renderMode)
Sets the render mode, which determines how the location updates will be rendered on the map.
|
public LocationLayerPlugin(@NonNull
com.mapbox.mapboxsdk.maps.MapView mapView,
@NonNull
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
@Nullable
com.mapbox.android.core.location.LocationEngine locationEngine)
mapView - the MapView to apply the LocationLayerPlugin tomapboxMap - the MapboxMap to apply the LocationLayerPlugin withlocationEngine - the LocationEngine this plugin should use to updatepublic LocationLayerPlugin(@NonNull
com.mapbox.mapboxsdk.maps.MapView mapView,
@NonNull
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
@Nullable
com.mapbox.android.core.location.LocationEngine locationEngine,
@StyleRes
int styleRes)
mapView - the MapView to apply the LocationLayerPlugin tomapboxMap - the MapboxMap to apply the LocationLayerPlugin withlocationEngine - the LocationEngine this plugin should use to updatestyleRes - customize the user location icons inside your apps style.xmlpublic LocationLayerPlugin(@NonNull
com.mapbox.mapboxsdk.maps.MapView mapView,
@NonNull
com.mapbox.mapboxsdk.maps.MapboxMap mapboxMap,
@Nullable
com.mapbox.android.core.location.LocationEngine locationEngine,
LocationLayerOptions options)
mapView - the MapView to apply the LocationLayerPlugin tomapboxMap - the MapboxMap to apply the LocationLayerPlugin withlocationEngine - the LocationEngine this plugin should use to updateoptions - to customize the user location icons inside your appspublic void setLocationLayerEnabled(boolean isEnabled)
isEnabled - true to show layers and enable camera, false otherwisepublic void setCameraMode(int cameraMode)
CameraMode.NONE: No camera trackingCameraMode.NONE_COMPASS: Camera does not track location, but does track compass bearingCameraMode.NONE_GPS: Camera does not track location, but does track GPS bearingCameraMode.TRACKING: Camera tracks the user locationCameraMode.TRACKING_COMPASS: Camera tracks the user location, with bearing provided by a compassCameraMode.TRACKING_GPS: Camera tracks the user location, with normalized bearingCameraMode.TRACKING_GPS_NORTH: Camera tracks the user location, with bearing always set to northcameraMode - one of the modes found in CameraModepublic int getCameraMode()
public void setRenderMode(int renderMode)
RenderMode.NORMAL: Shows user location, bearing ignoredRenderMode.COMPASS: Shows user location with bearing considered from compassRenderMode.GPS: Shows user location with bearing considered from locationrenderMode - one of the modes found in RenderModepublic int getRenderMode()
public LocationLayerOptions getLocationLayerOptions()
LocationLayerOptionspublic void applyStyle(@StyleRes
int styleRes)
styleRes - a XML style overriding some or all the optionspublic void applyStyle(LocationLayerOptions options)
options - to update the current stylepublic void forceLocationUpdate(@Nullable
android.location.Location location)
location - where the location icon is placed on the mappublic void setLocationEngine(@Nullable
com.mapbox.android.core.location.LocationEngine locationEngine)
If null is passed in, all updates will occur through the
forceLocationUpdate(Location) method.
locationEngine - a LocationEngine this plugin should use to handle updates@Nullable public com.mapbox.android.core.location.LocationEngine getLocationEngine()
LocationEngine being used for updating the user location layer.LocationEngine being used to update the user location layer@Nullable public android.location.Location getLastKnownLocation()
public void addCompassListener(@NonNull
CompassListener compassListener)
compassListener - a CompassListener for listening into compass heading and
accuracy changespublic void removeCompassListener(@NonNull
CompassListener compassListener)
compassListener - the CompassListener which you'd like to remove from the listener
list.public void addOnLocationClickListener(@NonNull
OnLocationLayerClickListener listener)
listener - The location layer click listener that is invoked when the
location layer is clickedpublic void removeOnLocationClickListener(@NonNull
OnLocationLayerClickListener listener)
listener - to be removedpublic void addOnLocationLongClickListener(@NonNull
OnLocationLayerLongClickListener listener)
listener - The location layer click listener that is invoked when the
location layer is clickedpublic void removeOnLocationLongClickListener(@NonNull
OnLocationLayerLongClickListener listener)
listener - to be removedpublic void addOnCameraTrackingChangedListener(@NonNull
OnCameraTrackingChangedListener listener)
listener - Listener that gets invoked when camera tracking state changes.public void removeOnCameraTrackingChangedListener(@NonNull
OnCameraTrackingChangedListener listener)
listener - Listener that gets invoked when camera tracking state changes.public void addOnLocationStaleListener(@NonNull
OnLocationStaleListener listener)
This timeout is set by LocationLayerOptions.staleStateTimeout().
listener - invoked when last update is considered stalepublic void removeOnLocationStaleListener(@NonNull
OnLocationStaleListener listener)
listener - to be removed from the listpublic void onStart()
onStart method. You'll also most likely want
to check that this Location Layer plugin instance inside your activity is null or not.public void onStop()
onStop method.