searchAroundPosition static method
- Coordinates position,
- void onComplete(), {
- String? textFilter,
- 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: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
position). - 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 (empty on error).
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);
}