Skip to content

[Feature request]: traffic data required in ios or any alternative to get live/Real time data #409

@altaf2892

Description

@altaf2892

Is there an existing issue for this?

  • I have searched the existing issues

Use case

/// Traffic data (Android only).
final RouteSegmentTrafficData? trafficData;

i have checked class and found above limitation also i just checked this officla link that provide traffic data for ios : https://developers.google.com/maps/documentation/navigation/ios-sdk/events .
but how to use or customize class to get those ios specfic data here in flutter package .

i have written code Android to get live traffic data check below. now i want for ios also but i saw limitation so ca u guide me like in offical page it says to get TrafficData in Ios aswell so how can i achieve this?

Android Live Traffic Data Code

Future<RouteSegmentTrafficDataRoadStretchRenderingDataStyle?> getUpcomingTrafficStyleWithin500m(NavInfo navInfo) async {
    try {
      // Reset everything on route change
      if (navInfo.routeChanged) {
        print("Route changed. Resetting traffic alert state.");
        hasShownTrafficAlert = false;

        offset = 0;
      }

      final RouteSegment? segment = await GoogleMapsNavigator.getCurrentRouteSegment();

      if (segment == null || segment.trafficData == null || segment.trafficData!.roadStretchRenderingDataList.isEmpty) {
        print('❌ No traffic data available.');
        return null;
      }

      final stretches = segment.trafficData!.roadStretchRenderingDataList;

      // Filter TrafficJam stretches only
      final slowerStretches =
          stretches.where((s) => s != null && s.style == RouteSegmentTrafficDataRoadStretchRenderingDataStyle.trafficJam).toList();

      if (slowerStretches.isEmpty) {
        print('✅ No slower traffic stretches available.');
        return null;
      }

      // Sort by offset and get the closest one within 500m
      slowerStretches.sort((a, b) => a!.offsetMeters.compareTo(b!.offsetMeters));

      final upcomingStretch = slowerStretches.firstWhere(
        (s) => s != null && s.offsetMeters <= 500,
        orElse: () => RouteSegmentTrafficDataRoadStretchRenderingData(
          style: RouteSegmentTrafficDataRoadStretchRenderingDataStyle.unknown,
          offsetMeters: -1,
          lengthMeters: 0,
        ),
      );
      if (upcomingStretch == null) {
        return null;
      }

      // If stretch not valid, skip
      if (upcomingStretch.offsetMeters < 0 || upcomingStretch.style == RouteSegmentTrafficDataRoadStretchRenderingDataStyle.unknown) {
        return null;
      }
      print("offsetMeters=> ${upcomingStretch.offsetMeters}");
      offset = upcomingStretch.offsetMeters;
      if (offset <= 0) {
        hasShownTrafficAlert = false;
        return null;
      }
      // offset: user is >=10m away from stretch
      //hasShownTrafficAlert= need to be false means alert not yet shown.
      //isStillTiltingUnknown() = device is not tilting or still
      // GoogleMapsNavigator.isGuidanceRunning() = navigation is running
      if (offset >= 10 &&
          !hasShownTrafficAlert &&
          isStillTiltingUnknown() == false &&
          await GoogleMapsNavigator.isGuidanceRunning()) {
        hasShownTrafficAlert = true;
        return upcomingStretch.style;
      }

    } catch (e) {
      print('🚨 Error getting traffic data: $e');
      return null;
    }
    return null;
  }
```
`

### Proposal

i need gauidance that how can i get live traffic data in ios aswell. 

Metadata

Metadata

Assignees

Labels

triage meI really want to be triaged.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions