drawRoutePolyline method
Implementation
Future<void> drawRoutePolyline(RouteDestination destination) async {
final myRoute = Polyline(
polylineId: const PolylineId('route'),
color: Colors.black,
width: 5,
points: destination.points,
startCap: Cap.roundCap,
endCap: Cap.roundCap);
final double distanceKm =
(((destination.distance / 1000) * 100).floorToDouble()) / 100;
final int tripDuration =
((destination.duration / 60).floorToDouble()).toInt();
final Marker startMarker = await generateCustomMarker(
id: 'start',
position: destination.points.first,
title: '$tripDuration',
subtitle: destination.initialPlace.placeName);
final Marker endMarker = await generateCustomMarker(
id: 'end',
position: destination.points.last,
title: '$distanceKm',
subtitle: destination.finishPlace.placeName);
final currentPolylines = Map<String, Polyline>.from(state.polylines);
currentPolylines['route'] = myRoute;
final currentMarkers = Map<String, Marker>.from(state.markers);
currentMarkers['start'] = startMarker;
currentMarkers['end'] = endMarker;
add(DisplayPolylinesEvent(currentPolylines, currentMarkers));
await Future.delayed(const Duration(milliseconds: 300));
_mapController?.showMarkerInfoWindow(const MarkerId('start'));
}