search static method
Search for address items under a specified parent landmark.
The search starts at parent and returns items matching filter at the requested detailLevel. If parent is the default
landmark, only AddressDetailLevel.country can be searched. The search will return results according to the session
preferences (for example, maximum matches and fuzzy matching).
This function should be used to progressively drill down the address hierarchy by using results from one search as the parent for the next level.
Parameters
filter: The text filter to apply. If empty, all items at the requested level are returned (subject to preferences limits).parent: The landmark to use as the starting point for the search.detailLevel: The detail level to search for (see AddressDetailLevel). Use getNextAddressDetailLevel to determine valid levels for a given parent.onComplete: Callback invoked when the search completes. It provides:err: The resulting GemError code for the operation.landmarks: List of matching landmarks (empty on failure).
Returns
- TaskHandler?: The associated TaskHandler if the search could be started; otherwise null.
Also see:
- getNextAddressDetailLevel - Determine valid next detail levels for a given parent landmark.
- GuidedAddressSearchPreferences - Configure preferences for guided address searches.
- getCountryLevelItem - Obtain country-level landmarks by ISO code.
Implementation
static TaskHandler? search(
final String filter,
final Landmark parent,
final AddressDetailLevel detailLevel,
final void Function(GemError err, List<Landmark> landmarks) onComplete,
) {
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(
'GuidedAddressSearchService',
'search',
args: <String, dynamic>{
'results': results.pointerId,
'parent': parent.pointerId,
'filter': filter,
'detailToSearch': detailLevel.id,
'progress': progListener.id,
},
);
final int errorCode = resultString['result'];
if (errorCode != GemError.success.code) {
onComplete(GemErrorExtension.fromCode(errorCode), <Landmark>[]);
return null;
}
return TaskHandlerImpl(progListener.id);
}