flutter_map_location_marker
一个用于显示设备当前位置的 flutter_map 插件。 
特点
-
自定义:位置标记可以完全自定义。精度圆和标题的颜色也可以自定义。
-
简单:不依赖其他图层。不需要
MapController或MarkerLayer。
用法
将 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
],
);
}
示例
-
标记自定义 将标记更改为您想要的任何 widget。
-
用于居中当前位置的浮动操作按钮 使用浮动操作按钮将地图移动和缩放到当前位置。
-
更改 Geolocator 设置 您可以自行定义 Geolocator 设置。
-
可选的距离过滤器 在运行时更改 Geolocator 设置。
-
自定义流 使用您自己的流,例如来自其他库的位置流或预定义的路线,作为源。