googlemaps / googlemaps/flutter-navigation-sdk

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

Open
#409 1 comment 0 reactions 1 assignee Claimed by @jokerttu View on GitHub
triage me type: feature request
Dominant language
Dart
Stars
75
Forks
54
Avg merge
4d 2h
Merged PRs (30d)
5

Description

### Is there an existing issue for this?

- [x] 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 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.