[Flutter - Mapbox GL]如何在初始地图加载时添加符号?

[Flutter - Mapbox GL]How to add Symbol on initial map load?

我尝试使用 mapController 的 addSymbol 方法添加地图标记,但显然该标记未显示在地图上

void _onMapCreated(MapboxMapController controller) async {
  mapController = controller;

  deviceMarker = await mapController!.addSymbol(SymbolOptions(
      geometry: LatLng(deviceLongitude, deviceLatitude),
      iconImage: "assets/map_marker_device.png",
      iconSize: 0.1,
      iconOffset: const Offset(0, -150)));
}

需要先加载图片,再手动提供给控制器;您传递给 iconImage 的字符串是任意的,只是标识您在 MapboxMapController .addImage

中提供的图像
Future<Uint8List> loadMarkerImage() async {
  var byteData = await rootBundle.load("assets/images/custom_marker.png");
  return byteData.buffer.asUint8List();
}

void _onMapCreated(MapboxMapController controller) async {
  var markerImage = await loadMarkerImage();

  controller.addImage('marker', markerImage);

  await controller.addSymbol(SymbolOptions(
      iconSize: 0.1,
      iconImage: "marker",
      geometry: location,
      iconOffset: const Offset(0, -150)));
  
}