UserLocationLayer class Location

Shows the user location on the MapLibreMap by using it in MapLibreMap.children, and moves the camera with it while tracking. It is a MapPlugin of the map.

The layer takes its locations from a stream, so it works the same on every platform and with any location source. It asks for no permission; use a package such as permission_handler or geolocator for that, and maplibre_geolocator to turn geolocator positions into locations.

A gesture that moves the map, such as a drag, a pinch or a scroll wheel zoom, stops the tracking and reports UserLocationTracking.none to onTrackingChanged.

The location shows as a dot, a circle of its accuracy and a cone of its heading, which style changes. They are style layers of the map, so the map draws them in the same frame as everything else, and the accuracy and the heading lie flat on a tilted map. anchor places them among the layers of the style, for example below its labels.

Inheritance

Constructors

UserLocationLayer({required Stream<UserLocation> locations, UserLocationTracking tracking = UserLocationTracking.none, ValueChanged<UserLocationTracking>? onTrackingChanged, double? trackingZoom, Duration trackingDuration = const Duration(milliseconds: 500), UserLocationStyle style = const UserLocationStyle(), LayerAnchor anchor = const LayerAnchor.top(), ValueChanged<UserLocation>? onClick, Key? key})
Creates a layer that shows the latest of locations.
const

Properties

anchor → LayerAnchor
Where the layers of the location go among the layers of the style, on top of them by default, see Layer.anchor.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
locations → Stream<UserLocation>
The locations of the user. The layer shows the latest one.
final
onClick → ValueChanged<UserLocation>?
Called when the user taps or clicks the location.
final
onTrackingChanged → ValueChanged<UserLocationTracking>?
Called when the tracking changes because the user moved the map.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
style → UserLocationStyle
How the location is drawn.
final
tracking → UserLocationTracking
How the camera moves with the user location.
final
trackingDuration → Duration
How long the camera takes to follow a new location.
final
trackingZoom → double?
The zoom the camera moves to when the tracking starts, or null to keep the zoom.
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<UserLocationLayer>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited