searchAlongRoute static method

TaskHandler? searchAlongRoute(
  1. Route route,
  2. void onComplete(
    1. GemError err,
    2. List<Landmark> results
    ), {
  3. String? textFilter,
  4. SearchPreferences? preferences,
})

Search for landmarks along a route.

Finds landmarks along the specified route, optionally filtered by textFilter.

Parameters

Returns

  • TaskHandler?: TaskHandler for this operation if search could be started; otherwise null.

See also:

  • Route - Represents the route along which to search for landmarks.
  • SearchPreferences - Configure search behavior (fuzzy matching, onboard-only, max results, etc.).

Implementation

static TaskHandler? searchAlongRoute(
  final Route route,
  final void Function(GemError err, List<Landmark> results) onComplete, {
  final String? textFilter,
  SearchPreferences? preferences,
}) {
  preferences ??= SearchPreferences();

  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);
  final LandmarkList results = LandmarkList();

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

    if (err == GemError.success.code || err == GemError.reducedResult.code) {
      onComplete(GemErrorExtension.fromCode(err), results.toList());
    } else {
      onComplete(GemErrorExtension.fromCode(err), <Landmark>[]);
    }
  });

  final OperationResult resultString = staticMethod(
    'SearchService',
    'searchAlongRoute',
    args: <String, dynamic>{
      'results': results.pointerId,
      'listener': progListener.id,
      'route': route.pointerId,
      if (textFilter != null) 'textFilter': textFilter,
      'preferences': preferences.pointerId,
    },
  );

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

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

  return TaskHandlerImpl(progListener.id);
}