calculateRoute static method

TaskHandler? calculateRoute(
  1. List<Landmark> waypoints,
  2. RoutePreferences routePreferences,
  3. void onCompleteCallback(
    1. GemError err,
    2. List<Route> routes
    )
)

Calculate a route between the specified waypoints.

Parameters

  • IN waypoints The list of waypoints for the route
  • IN routePreferences The preferences for the route calculation
  • IN onCompleteCallback Will be invoked when the search operation is completed, providing the search results and an error code.
    • Will be called with GemError.success error and non-empty routes upon success.
    • Will be called with GemError.notSupported if the provided routing preferences contain an unsupported configuration
    • Will be called with GemError.invalidInput if the calculation input contains invalid data, e.g. waypoints.length < 1 < 2 for path result or waypoints.length < 1 for range result type
    • Will be called with GemError.cancel if the route calculation was canceled by the user
    • Will be called with GemError.waypointAccess if a route couldn't be found using the provided routing preferences
    • Will be called with GemError.connectionRequired if the routing preferences RoutePreferences.allowOnlineCalculation = false and the calculation cannot be done on client side due to missing necessary data
    • Will be called with GemError.expired if the calculation cannot be done on client side due to missing necessary data and the client world map data version is no longer supported by the online routing service
    • Will be called with GemError.routeTooLong if the routing was executed on the online service and the operation took too much time to complete ( usually more than 1 min, depending on the server overload state )
    • Will be called with GemError.invalidated if the offline map data changed ( offline map downloaded, erased, updated ) during the calculation
    • Will be called with GemError.noMemory if the routing engine couldn't allocate the necessary memory for the calculation

Returns

  • The TaskHandler associated with the route calculation if it can be started otherwise null.

Throws

  • An exception if it fails.

Implementation

static TaskHandler? calculateRoute(
  final List<Landmark> waypoints,
  final RoutePreferences routePreferences,
  final void Function(GemError err, List<Route> routes) onCompleteCallback,
) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
  final RouteList results = RouteList();

  final LandmarkList waypointsList = LandmarkList.fromList(waypoints);

  progListener.registerOnCompleteWithDataCallback((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(progListener.id);

    if (err == GemError.success.code) {
      onCompleteCallback(GemErrorExtension.fromCode(err), results.toList());
    } else {
      onCompleteCallback(GemErrorExtension.fromCode(err), <Route>[]);
    }
  });

  final OperationResult result = staticMethod(
    'RoutingService',
    'calculateRoute',
    args: <String, dynamic>{
      'results': results.pointerId,
      'listener': progListener.id,
      'waypoints': waypointsList.pointerId,
      'routePreferences': routePreferences,
    },
  );

  final GemError errorCode = GemErrorExtension.fromCode(result['result']);

  if (errorCode != GemError.success) {
    onCompleteCallback(errorCode, <Route>[]);
    return null;
  }

  return TaskHandlerImpl(progListener.id);
}