widget_marker_google_map
带有 widget 标记的 Google 地图。
设置
请按照 google_maps_flutter 文档中的步骤进行操作。
用法
与 google_maps_flutter 相同,只是增加了 widgetMarkers。
WidgetMarkerGoogleMap(
initialCameraPosition: shibuya,
mapType: MapType.normal,
widgetMarkers: [
WidgetMarker(
position: cafePosition,
markerId: 'cafe',
widget: Container(
color: Colors.brown,
padding: const EdgeInsets.all(2),
child: const Icon(
Icons.coffee,
color: Colors.white,
size: 64,
),
),
),
WidgetMarker(
position: clothesShopPosition,
markerId: 'clothes',
widget: Container(
color: Colors.green,
padding: const EdgeInsets.all(4),
child: const Text(
'shop',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 32,
),
),
),
),
WidgetMarker(
position: hamburgerShopPosition,
markerId: 'hamburger',
widget: Container(
color: Colors.red,
padding: const EdgeInsets.all(2),
child: const Icon(
Icons.fastfood,
color: Colors.yellow,
size: 64,
),
),
),
],
),
WidgetMarker
您需要插入 WidgetMarker 列表才能使用 widget 标记。
请确保在使用手势时仍需要使用 onTap 方法。
class WidgetMarker {
WidgetMarker({
required this.position,
required this.markerId,
required this.widget,
this.onTap,
}) : assert(markerId.isNotEmpty);
final LatLng position;
/// Keep this unique, otherwise it will not appear.
final String markerId;
/// Gestures of widget is disabled.
/// Use this callback instead.
final VoidCallback? onTap;
final Widget widget;
}
如果您有任何请求或问题,请随时在 GitHub 上提问。
