searchAroundPosition static method

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

Search for landmarks around a position.

Finds landmarks in the closest proximity to position, optionally filtered by textFilter. If no text filter is provided, all landmarks near the position are returned (limited by preferences).

Parameters

  • position: The geographic position to search around.
  • onComplete: Callback invoked when the search completes. Provides:
  • textFilter: Optional text filter to narrow results.
  • preferences: Optional SearchPreferences to customize search behavior.

Returns

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

Implementation

static TaskHandler? searchAroundPosition(
  final Coordinates position,
  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',
    'searchAroundPosition',
    args: <String, dynamic>{
      'results': results.pointerId,
      'listener': progListener.id,
      'position': position,
      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);
}