我希望使用.svg图像作为图标放置标记。我正在使用google_maps_flutter库。这适用于.png转换后的图像,但我找不到直接使用.svg文件的方法。
阅读此问题后,我将在此发布:在google_maps_flutter Flutter插件中使用SVG标记
并尝试使用此线程中所述的fromAssetImage方法:如何在Flutter中更改Google Map标记的图标大小?
我希望这个新版本的库可以帮助解决我的问题。
我尝试使用以下代码解决它:
MapWidget类
for (Place place in widget.places) {
place.toMarker(
context,
() => _onPlaceTapped(place),
).then(setState((){
markerSet.add
}));
}
Run Code Online (Sandbox Code Playgroud)
地方课程
Future<Marker> toMarker(BuildContext context, VoidCallback onTap) async {
return Marker(
markerId: MarkerId(id.toString()),
position: LatLng(lat, lon),
icon: await category.markerIcon(createLocalImageConfiguration(context)),
onTap: onTap,
);
Run Code Online (Sandbox Code Playgroud)
类别类
Future<BitmapDescriptor> markerIcon(ImageConfiguration configuration) async {
BitmapDescriptor b;
switch (type) {
case CategoryType.FirstCategory:
b = await BitmapDescriptor.fromAssetImage(configuration, 'assets/markers/marker-first.svg');
break;
case CategoryType.SecondCategory:
b = await BitmapDescriptor.fromAssetImage(configuration, 'assets/markers/marker-second.svg');
break;
default:
b = await BitmapDescriptor.fromAssetImage(configuration, 'assets/markers/marker-third.svg');
break; …Run Code Online (Sandbox Code Playgroud)