getHazardsNear method

Future<List<Report>> getHazardsNear(
  1. RaliPosition position,
  2. double radiusKm
)

//////////// //////////// Gets all hazards near a specific location (user reports + Mapbox data)

Implementation

// II.C - Hazard Query Methods
///////////////
/// Gets all hazards near a specific location (user reports + Mapbox data)
Future<List<Report>> getHazardsNear(RaliPosition position, double radiusKm) async {
  try {
    final List<Report> combinedResults = [];

    // Get user reports from Firebase - convert RaliPosition to GeoPoint
    final geoPoint = GeoPoint(position.lat, position.lng);
    final userReports = await _reportService.getReportsNear(geoPoint, radiusKm);
    combinedResults.addAll(userReports);

    // If combining results is enabled, get Mapbox hazards
    if (_combineResults) {
      final mapboxHazards = await _mapboxService.getRoadHazardsInArea(position, radiusKm);

      // Convert Mapbox incidents to Report format
      for (final hazard in mapboxHazards) {
        final report = _mapboxService.convertIncidentToReport(hazard);
        combinedResults.add(report);
      }
    }

    return combinedResults;
  } catch (e) {
    print('Error getting combined hazards: $e');
    return [];
  }
}