Text Search
In this guide you will learn how to do a text search and select a result to be displayed on an interactive map.
How it works
This example demonstrates the following features:
- Search for landmarks using a text input, with results being displayed on an interactive map.
Handling Search Button tap
This is the method to navigate to the search screen, defined in the SearchPage() widget, in search_page.dart
As text is typed in the text field by the user, the _onSearchSubmitted() function is called, which creates a preferences instance and then the search() function is called.
The coordinates of the current location displayed on the map widget.coordinates are used for comparison, to compute the distance to the positions of the search results.
The search() function calls the SearchService.search() , obtains a list of landmarks in results , which are then displayed as a text list. Tapping on a result causes the map to be centered on the position of that search result.
This is done in the method that calls SearchPage() above.
The result landmark tapped by the user is selected:
Then the map is centered on the coordinates of that result landmark: