首页 > 解决方案 > BitmapDescriptor.fromBytes 在 iOS 上不起作用,但在 Android 上运行良好

问题描述

我尝试将 BitmapDescriptor.fromBytes 用于谷歌地图标记的图标。该用法在 Android 上运行良好,并在地图标记中显示图标。这是我的逻辑功能代码:

void convertToImg({BuildContext context,List<DataEvent> data}) async{
 for(int i=0;i<data.length;i++) {
   final http.Response res = await http.get(data[i].category.icon);
   DrawableRoot root = await svg.fromSvgBytes(res.bodyBytes, null);
   ui.Picture picture = root.toPicture(size: Size(16, 16));
   ui.Image image = await picture.toImage(16, 16);
   ByteData byteData = await image.toByteData(format: ui
       .ImageByteFormat.png);
   listImg.add(byteData.buffer.asUint8List());
 }
}

这是我的标记代码:

void addMarker({List<DataEvent> data}) {
 markers = Iterable.generate(data.length, (index) {
   return Marker(
     markerId: MarkerId("${data[index].id}"),
     position: LatLng(
       double.parse(data[index].location.split(',')[0]),
       double.parse(data[index].location.split(',')[1])
     ),
     infoWindow: InfoWindow(
       title: data[index].name,
       snippet: data[index].description,
       anchor: Offset(1.5, 1.5)
     ),
     icon: BitmapDescriptor.fromBytes(listImg[index])
   );
 });
}

有谁知道为什么?

这是两个结果。图标就像一条小白墨鱼

标签: flutterdartgoogle-maps-flutter

解决方案


推荐阅读