search static method

TaskHandler? search(
  1. String textFilter,
  2. Coordinates referenceCoordinates,
  3. void onComplete(
    1. GemError err,
    2. List<Landmark> results
    ), {
  4. SearchPreferences? preferences,
  5. RectangleGeographicArea? locationHint,
})

Search for landmarks using text and reference coordinates.

Performs a text-based search centered around referenceCoordinates. Results are ordered by relevance to this position. Optionally, provide locationHint to restrict search to a specific area.

Parameters

  • textFilter: Text to filter results (e.g., "Paris").
  • referenceCoordinates: The reference position for result relevance ordering. Landmarks closer to this position are ranked higher.
  • onComplete: Callback invoked when the search completes. Provides:
  • preferences: Optional SearchPreferences to customize search behavior.
  • locationHint: Optional area to restrict search.

Returns

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

Example

SearchService.search("Paris", coords, preferences: preferences, (err, results) {
  if (err == GemError.success) {
    print("Found ${results.length} results");
  } else {
    print("Error: $err");
  }
});

See also:

  • SearchPreferences - Configure search behavior (fuzzy matching, onboard-only, max results, etc.).
  • Landmark - Represents places of interest returned by search operations.

Implementation

static TaskHandler? search(
  final String textFilter,
  final Coordinates referenceCoordinates,
  final void Function(GemError err, List<Landmark> results) onComplete, {
  SearchPreferences? preferences,
  final RectangleGeographicArea? locationHint,
}) {
  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',
    'search',
    args: <String, dynamic>{
      'results': results.pointerId,
      'listener': progListener.id,
      'textFilter': textFilter,
      'referenceCoordinates': referenceCoordinates,
      'preferences': preferences.pointerId,
      'locationHint':
          locationHint ??
          RectangleGeographicArea(
            topLeft: Coordinates(),
            bottomRight: Coordinates(),
          ),
    },
  );

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

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

  return TaskHandlerImpl(progListener.id);
}