A flutter_map plugin for displaying device current location.
Join flutter_map Discord server. Talk
about flutter_map_location_marker
, get and give help in #plugins channel.
-
Simple: The only thing to do is adding a
CurrentLocationLayer()
in to your map because all parameters have good default values. -
Flexible: The default implementation is receiving device's position from the geolocator package and receiving device's heading from the flutter_compass package, but with type conversion, streams from other source are also supported.
-
Auto-following: The map follow the new location when location is updated. This feature is disabled by default.
-
Auto-rotating: The map can be rotated automatically as navigation mode. This feature is disabled by default.
-
Customization: The location marker can be fully customized, even the colors of accuracy circle and header.
Add flutter_map_location_marker to your pubspec.yaml:
dependencies:
flutter_map_location_marker: any // or latest verion
Add permission, please follow the instruction from geolocator package.
Add the layer widget into FlutterMap
:
Widget build(BuildContext context) {
return FlutterMap(
children: [
TileLayer(
urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
maxZoom: 19,
),
CurrentLocationLayer(), // <-- add layer here
],
);
}
Discover more parameters in CurrentLocationLayer .
Widget build() {
return CurrentLocationLayer(
followOnLocationUpdate: FollowOnLocationUpdate.always,
turnOnHeadingUpdate: TurnOnHeadingUpdate.never,
style: LocationMarkerStyle(
marker: const DefaultLocationMarker(
child: Icon(
Icons.navigation,
color: Colors.white,
),
),
markerSize: const Size(40, 40),
markerDirection: MarkerDirection.heading,
),
);
}
If multiple location markers is needed to display, consider using AnimatedLocationMarkerLayer or LocationMarkerLayer .
-
Marker Customization : Change the marker to any widget you want.
-
Floating Action Button to Follow Current Location : Use a floating action button to move and zoom the map to current location.
-
Change Geolocator Settings : Define Geolocator settings yourself.
-
Selectable Distance Filter : Change Geolocator settings at the runtime.
-
Custom Stream : Use your own stream, such as position stream from other library or predefined route, as the source.
-
No Stream : Use Flutter
setState()
to update position and heading. -
Navigation Mode : Rotate the map to keep heading pointing upward.
-
Default Stream : Share the default streams between your app and this plugin.
Q: How to get the positionStream , headingStream or their origin streams from a CurrentLocationLayer widget?
A: No. You should not get value from a widget, instead, create the stream you need and also pass it to the widget. You may see this example to know about how to do this.