I have page with Google Maps. In it i show a lot of markers. I use FireStore to store marker data such as latlng, title and icon. Latlng and Title working fine, i managed to display my markers from Firestore into my App. Now i want to display my icons as well. Icon node stored as access token to Firebase Storage path. In it i have .svg icon donwloaded from Google Fonts. Now, how can i show them as Google Maps Marker Icon's?
Here is my code:
class _LocationPageState extends State<LocationPage> {
Completer<GoogleMapController> _controller = Completer();
late BitmapDescriptor sourceIcon;
late BitmapDescriptor destinationIcon;
late LatLng currentLocation;
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
@override
void initState() {
super.initState();
getMarkerData();
}
static const _initialCameraPosition = CameraPosition(
target: LatLng(43.24155902529146, 76.9519522293528),
zoom: 17,
);
void initMarker(specify, specifyId) async {
var markerIdVal = specifyId;
final MarkerId markerId = MarkerId(markerIdVal);
final Marker marker = Marker(
markerId: markerId,
position: LatLng(specify['latlng'].latitude, specify['latlng'].longitude),
infoWindow: InfoWindow(title: specify['title']),
);
setState(() {
markers[markerId] = marker;
});
}
getMarkerData() async {
FirebaseFirestore.instance.collection('location').get().then((markerData) {
if (markerData.docs.isNotEmpty) {
for (int i = 0; i < markerData.docs.length; i++) {
initMarker(markerData.docs[i].data(), markerData.docs[i].id);
}
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: MainTheme.lightTheme.primaryColor,
automaticallyImplyLeading: true,
title: Text('Локация',
textAlign: TextAlign.center,
style: MainTheme.lightTheme.textTheme.headline2),
elevation: 4,
),
body: GoogleMap(
markers: Set<Marker>.of(markers.values),
myLocationButtonEnabled: false,
zoomControlsEnabled: false,
initialCameraPosition: _initialCameraPosition,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
),
);
}
}