I wish to place markers using .svg images as icons. I am using google_maps_flutter library. This worked with .png converted images but I didn't find a way to use .svg files directly.
I am posting here after reading this issue : Using SVG markers in google_maps_flutter Flutter plugin
And trying to use the method fromAssetImage as described in this thread : How to change the icon size of Google Map marker in Flutter?
I hoped that this new version of the library would help solve my issue.
I tried solving it with the following code :
MapWidget class
for (Place place in widget.places) {
place.toMarker(
context,
() => _onPlaceTapped(place),
).then(setState((){
markerSet.add
}));
}
Place class
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,
);
Category class
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;
}
return b;
}
The images' path is already added to pubspec.yaml if you are wondering.
I expected the default red google markers to be replaced by some custom markers (there should be a small icon image on each custom marker) on the map, however only default markers are shown (not the default in the switch statement, I am speaking of google's default markers).
There is no error message using iOS simulator and google_maps_flutter 0.5.15+1 library version.