我尝试将 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])
);
});
}
有谁知道为什么?