search static method
- String textFilter,
- Coordinates referenceCoordinates,
- void onComplete(), {
- SearchPreferences? preferences,
- 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:err: The result status. Possible values:- GemError.success: Search completed successfully with results.
- GemError.reducedResult: Search completed successfully but only a subset of results was returned.
- GemError.invalidInput: Invalid input (e.g., invalid
referenceCoordinates). - GemError.cancel: Search canceled by user.
- GemError.noMemory: Insufficient memory for operation.
- GemError.operationTimeout: Operation timeout on online service (typically > 1 min).
- GemError.networkFailed: Network failure during online search.
results: List of found landmarks if the error is GemError.success. Empty list on error.
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);
}