fetchRoute method
Retrieves the full GeoJSON route for a given trip.
Fetches a complete route representation for the specified trip using the
device-side Kruzr SDK. The returned data is parsed into a
GeoJsonFeatureCollection, containing structured geographic features such as:
- Route LineString: Full trip path
- Start Location Point
- End Location Point
- Driving Event Points (speeding, hard braking, harsh acceleration)
- Segment Highlight LineStrings (speeding streaks, adverse events, etc.)
Each feature retains its geometry (Point/LineString) and properties
such as:
highlight_typestrokestroke-widthscoreStatsstartTime
This structure can be used in any map renderer, including:
- Custom canvas-based maps
- flutter_map / MapLibre / Leaflet
- Mapbox layers
- Any GeoJSON-compatible visualization engine
Returns:
GeoJsonFeatureCollection?: A parsed collection of route features, ornullif unavailable.
Usage Example:
try {
final route = await communicator.fetchRoute("2985_1764285633333");
if (route != null) {
for (final feature in route.collection!) {
print("Feature type: ${feature.type}");
print("Geometry: ${feature.geometry?.type}");
print("Properties: ${feature.properties}");
// Handle Point
if (feature.geometry is GeoJsonPoint) {
final p = feature.geometry as GeoJsonPoint;
print("Point: ${p.geoPoint.latitude}, ${p.geoPoint.longitude}");
}
// Handle LineString
if (feature.geometry is GeoJsonLineString) {
final line = feature.geometry as GeoJsonLineString;
print("Segment points: ${line.geoSerie.geoPoints}");
}
}
}
} catch (e) {
print('Failed to fetch route: $e');
}
Common Route Highlight Types:
ROUTE_START_LOCATIONROUTE_END_LOCATIONOVERALL_SCORESPEEDINGHARD_BRAKINGHARD_ACCELERATIONDISTRACTIONLANE_CHANGEDROWSY
Use Cases:
- Trip visualization in apps
- Highlighting critical driving segments
- Custom route replay rendering
- Heatmaps / behavioural analysis
- Event-based map overlays
- Route summary screens & timeline views
Throws:
Future.error("Unable to fetch route"): If the route cannot be retrieved from the native SDK.
Implementation
Future<GeoJSONFeatureCollection?> fetchRoute(String appTripId) async {
try {
return await kruzr_comm.fetchRoute(appTripId);
} on Exception catch (e, stackTrace) {
if (kDebugMode) {
print("Error in fetchRoute");
print(stackTrace);
print(e);
}
return Future.error("Unable to fetch route");
}
}