flutter_map_location_marker

pub package github tag license

一个用于显示设备当前位置的 flutter_map 插件。 界面预览

特点

  • 自定义:位置标记可以完全自定义。精度圆和标题的颜色也可以自定义。

  • 简单:不依赖其他图层。不需要 MapControllerMarkerLayer

用法

将 flutter_map_location_marker 添加到您的 pubspec.yaml 文件中

dependencies:
  flutter_map_location_marker: any // or latest verion

添加权限,请遵循 geolocation 包的说明。

将图层 widget 添加到 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
    ],
  );
}

或者,您可以使用旧样式创建图层

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
    ],
  );
}

示例

  1. 标记自定义 将标记更改为您想要的任何 widget。

  2. 用于居中当前位置的浮动操作按钮 使用浮动操作按钮将地图移动和缩放到当前位置。

  3. 更改 Geolocator 设置 您可以自行定义 Geolocator 设置。

  4. 可选的距离过滤器 在运行时更改 Geolocator 设置。

  5. 自定义流 使用您自己的流,例如来自其他库的位置流或预定义的路线,作为源。

GitHub

查看 Github