Getting started with Search
The Maps SDK for Flutter provides a flexible and robust search functionality, allowing the search of locations using text queries and coordinates:
- Text Search: Perform searches using a text query and geographic coordinates to prioritize results within a specific area.
- Search Preferences: Customize search behavior using various options, such as allowing fuzzy results, limiting search distance, or specifying the number of results.
- Category-Based Search: Filter search results by predefined categories, such as gas stations or parking areas.
- Proximity Search: Retrieve all nearby landmarks without specifying a text query.
Text search
The simplest way to search for something is by providing text and specifying coordinates. The coordinates serve as a hint, prioritizing points of interest (POIs) within the indicated area.
const text = "Paris";
final coords = Coordinates(latitude: 45, longitude: 10);
final preferences = SearchPreferences(
maxMatches: 40,
allowFuzzyResults: true,
);
TaskHandler? taskHandler = SearchService.search(
text,
coords,
preferences: preferences,
(err, results) async {
// If there is an error or there aren't any results, the method will return an empty list.
if (err == GemError.success) {
if (results.isEmpty) {
showSnackbar("No results");
} else {
showSnackbar("Number of results: ${results.length}");
}
} else {
showSnackbar("Error: $err");
}
},
);
note
The SearchService.search
method returns null
only when the geographic search fails to initialize. In such cases, calling SearchService.cancelSearch(taskHandler)
is not possible. Error details will be delivered through the onCompleteCallback
function of the SearchService.search
method.
The err
provided by the callback function can have the following values:
Value | Significance |
---|---|
GemError.success | successfully completed |
GemError.cancel | cancelled by the user |
GemError.noMemory | search engine couldn't allocate the necessary memory for the operation |
GemError.operationTimeout | 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.networkTimeout | can't establish the connection or the server didn't respond on time |
GemError.networkFailed | search was executed on the online service and the operation failed due to bad network connection |