calculateRoute static method
Calculates 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 onComplete Callback invoked when the search operation is completed, providing the search results and an error code.
- Called with GemError.success and non-empty routes upon success.
- Called with GemError.notSupported if the provided routing preferences contain an unsupported configuration.
- Called with GemError.invalidInput if the calculation input contains invalid data, e.g.
waypoints
.length < 2 for path result orwaypoints
.length < 1 for range result type. - Called with GemError.cancel if the route calculation was canceled by the user.
- Called with GemError.waypointAccess if a route couldn't be found using the provided routing preferences.
- Called with GemError.connectionRequired if RoutePreferences.allowOnlineCalculation is false and the calculation cannot be done on client side due to missing necessary data.
- 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.
- 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).
- Called with GemError.invalidated if the offline map data changed (offline map downloaded, erased, updated) during the calculation.
- 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.
Implementation
static TaskHandler? calculateRoute(
final List<Landmark> waypoints,
final RoutePreferences routePreferences,
final void Function(GemError err, List<Route> routes) onComplete,
) {
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) {
onComplete(GemErrorExtension.fromCode(err), results.toList());
} else {
onComplete(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) {
onComplete(errorCode, <Route>[]);
return null;
}
return TaskHandlerImpl(progListener.id);
}