getPersistentRoadblockPathPreview static method

(List<Coordinates>, UserRoadblockPathPreviewCoordinate, GemError) getPersistentRoadblockPathPreview({
  1. required UserRoadblockPathPreviewCoordinate from,
  2. required Coordinates to,
  3. required RouteTransportMode transportMode,
})

Returns a preview of a persistent roadblock path between two coordinates.

The preview is calculated for the specified transportMode and returns the list of coordinates representing the suggested path, a preview coordinate to indicate the next likely roadblock match, and a GemError describing success or any failure.

The from parameter should be obtained from a previous call to this method or created via UserRoadblockPathPreviewCoordinate.fromCoordinates for the initial call.

At the end of the operation, the returned coordinates can be used to create a path TrafficEvent representing the roadblock via the addPersistentRoadblockByCoordinates method.

Parameters

Returns

Example

Create a new UserRoadblockPathPreviewCoordinate for the starting point:

UserRoadblockPathPreviewCoordinate preview = UserRoadblockPathPreviewCoordinate.fromCoordinates(startCoordinates);

Call the method to get the subsequent UserRoadblockPathPreviewCoordinate based on the previous one:

final (coordinates, newPreviewStart, previewError) =
  TrafficService.getPersistentRoadblockPathPreview(
  from: preview,
  to: nextCoordinates,
  transportMode: RouteTransportMode.car,
);

if (previewError == GemError.success) {
  preview = newPreviewStart;
}

Also see:

Implementation

static (List<Coordinates>, UserRoadblockPathPreviewCoordinate, GemError)
getPersistentRoadblockPathPreview({
  required UserRoadblockPathPreviewCoordinate from,
  required Coordinates to,
  required RouteTransportMode transportMode,
}) {
  final OperationResult resultString = staticMethod(
    'TrafficService',
    'getPersistentRoadblockPathPreview',
    args: <String, dynamic>{
      'from': from,
      'to': to,
      'transportMode': transportMode.id,
    },
  );

  final List<Coordinates> coordinates =
      (resultString['result']['coords'] as List<dynamic>)
          .map((dynamic e) => Coordinates.fromJson(e))
          .toList();
  final UserRoadblockPathPreviewCoordinate previewCoordinate =
      UserRoadblockPathPreviewCoordinate.fromJson(
        resultString['result']['preview'],
      );
  final GemError error = GemErrorExtension.fromCode(
    resultString['result']['error'],
  );

  return (coordinates, previewCoordinate, error);
}