searchInArea static method

TaskHandler? searchInArea(
  1. RectangleGeographicArea area,
  2. Coordinates referenceCoordinates,
  3. void onCompleteCallback(
    1. GemError err,
    2. List<Landmark> results
    ), {
  4. String textFilter = '',
  5. SearchPreferences? preferences,
})

Get list of landmarks in the given geographic area.

Parameters

  • IN area The search target area.
  • IN referenceCoordinates The reference position. Results will be relevant to this position.
  • IN onCompleteCallback Will be invoked when the search operation is completed, providing the search results and an error code.
    • GemError.success and a non-empty list of landmarks if the search was successfully completed
    • GemError.reducedResult and a non-empty list of landmarks if the search was successfully completed but only a subset of results were returned
    • GemError.cancel if the search was canceled by the user
    • GemError.noMemory if the search engine couldn't allocate the necessary memory for the operation
    • GemError.operationTimeout if the search 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 )
    • GemError.networkFailed if the search was executed on the online service and the operation failed due to bad network connection
  • IN textFilter The optional text filter. Optional.
  • IN preferences The search preferences. Optional.

Returns

  • Associated TaskHandler for this operation if the search can be started otherwise null.

Throws

  • An exception if it fails.

Implementation

static TaskHandler? searchInArea(
  final RectangleGeographicArea area,
  final Coordinates referenceCoordinates,
  final void Function(GemError err, List<Landmark> results)
      onCompleteCallback, {
  final String textFilter = '',
  SearchPreferences? preferences,
}) {
  preferences ??= SearchPreferences();

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

  progListener.registerOnCompleteWithDataCallback((
    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) {
      onCompleteCallback(GemErrorExtension.fromCode(err), results.toList());
    } else {
      onCompleteCallback(GemErrorExtension.fromCode(err), <Landmark>[]);
    }
  });

  final String resultString = GemKitPlatform.instance.callObjectMethod(
    jsonEncode(<String, Object>{
      'id': 0,
      'class': 'SearchService',
      'method': 'searchInArea',
      'args': <String, dynamic>{
        'results': results.pointerId,
        'listener': progListener.id,
        'textFilter': textFilter,
        'referenceCoordinates': referenceCoordinates,
        'preferences': preferences.pointerId,
        'area': area,
      },
    }),
  );

  final dynamic decodedVal = jsonDecode(resultString);
  final GemError errorCode = GemErrorExtension.fromCode(decodedVal['result']);

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

  return TaskHandlerImpl(progListener.id);
}