addMarkersForPolylines method
addMarkersForPolylines method adds markers for the polylines on the map. It takes no parameters and adds markers for the polylines on the map.
Implementation
void addMarkersForPolylines() {
for (Polyline polyline in _polylines) {
List<LatLng> polylinePoints = polyline.points;
// Check if polyline has exactly 2 points
if (polylinePoints.length == 2) {
LatLng start = polylinePoints[0];
LatLng end = polylinePoints[1];
// Interpolate points
List<LatLng> intermediatePoints = interpolatePoints(start, end, 5);
// Create markers for each interpolated point
for (LatLng point in intermediatePoints) {
final markerId = 'marker_${point.latitude}_${point.longitude}';
final marker = Marker(
markerId: MarkerId(markerId),
position: point,
icon: _iconMarker ?? BitmapDescriptor.defaultMarker,
);
_markers.add(marker);
if (_polylineMarkers[polyline] == null) {
_polylineMarkers[polyline] = [marker];
} else {
_polylineMarkers[polyline]!.add(marker);
}
}
}
}
notifyListeners();
}