search static method
- String textFilter,
- Coordinates referenceCoordinates,
- void onCompleteCallback(), {
- SearchPreferences? preferences,
- RectangleGeographicArea? locationHint,
Search using text and geographic area as discriminants.
Parameters
- IN textFilter The text filter.
- 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.invalidInput if the search input is invalid, e.g. referenceCoordinates are invalids
- 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 preferences The search preferences. Optional.
- IN locationHint The location hint. The search will be restricted to the provided geographic area. Optional.
Returns
- Associated TaskHandler for this operation if the search can be started otherwise null.
Throws
- An exception if it fails.
Implementation
static TaskHandler? search(
final String textFilter,
final Coordinates referenceCoordinates,
final void Function(GemError err, List<Landmark> results)
onCompleteCallback, {
SearchPreferences? preferences,
final RectangleGeographicArea? locationHint,
}) {
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': 'search',
'args': <String, dynamic>{
'results': results.pointerId,
'listener': progListener.id,
'textFilter': textFilter,
'referenceCoordinates': referenceCoordinates,
'preferences': preferences.pointerId,
if (locationHint != null) 'locationHint': locationHint,
},
}),
);
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);
}