flutter_map_location_marker

pub package github tag license

A flutter_map plugin for displaying device current location. Interface preview

Join flutter_map Discord server. Talk about flutter_map_location_marker, get and give help in #plugins channel.

Features

  • Simple: The only thing to do is adding a LocationMarkerLayerWidget() 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-centering: The map center on 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.

Usage

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: [
      TileLayerWidget(
        options: TileLayerOptions(
          urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
          subdomains: ['a', 'b', 'c'],
        ),
      ),
      LocationMarkerLayerWidget(), // <-- add layer widget here
    ],
  );
}

Alternatively, you can use the old style to create the layer:

Widget build(BuildContext context) {
  return FlutterMap(
    options: MapOptions(
      plugins: [
        LocationMarkerPlugin(), // <-- add plugin here
      ],
    ),
    layers: [
      TileLayerOptions(
        urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        subdomains: ['a', 'b', 'c'],
      ),
      LocationMarkerLayerOptions(), // <-- add layer options here
    ],
  );
}

Discover more parameters in LocationMarkerPlugin and LocationMarkerLayerOptions .

Widget build() {
  return LocationMarkerLayerWidget(
    plugin: LocationMarkerPlugin(
      centerOnLocationUpdate: CenterOnLocationUpdate.always,
      turnOnHeadingUpdate: TurnOnHeadingUpdate.never,
    ),
    options: LocationMarkerLayerOptions(
      marker: const DefaultLocationMarker(
        child: Icon(
          Icons.navigation,
          color: Colors.white,
        ),
      ),
      markerSize: const Size(40, 40),
      markerDirection: MarkerDirection.heading,
    ),
  );
}

Examples

  1. Marker Customization : Change the marker to any widget you want.

  2. Floating Action Button for Centering Current Location : Use a floating action button to move and zoom the map to current location.

  3. Change Geolocator Settings : Define Geolocator settings yourself.

  4. Selectable Distance Filter : Change Geolocator settings at the runtime.

  5. Custom Stream : Use your own stream, such as position stream from other library or predefined route, as the source.

  6. Navigation Mode : Rotate the map to keep heading pointing upward.

Libraries

flutter_map_location_marker
A flutter_map plugin for displaying device current location.