Search
Search for a Location
Our goal now is to enable the user to interact with a search bar and move the map with respect to their search. Therefore, we need to implement a bit more functionality into our ViewController class, so feel free to update it as followed.
Let us start off by implementing the search bar. In this case, we add the following variables to our class. The vertical offset of the search bar here is simply to avoid the search bar from colliding with the navigation bar. The tableView will be used to allow the user to see and interact with the search results.
And let us also make sure the search bar delegated and correctly displayed in our view.
Finally, let us add the functions neccessary for our class to conform to the UITableViewDataSource protocol and the actual search button functionality.
Here, the first 3 functions simply outline the appearence of the table. Namely, how many rows to show and which text to represent each entry.
The main functions of note in this case are, func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
and func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
.
The former denotes what to do once an item is selected, in this case we simply go to the specified location and hide the table view again, while the latter functions almost exactly the same as the initial simple search we included in Display a Map with MapsIndoors.
At this point we should have a functional map with a search feature.
Expected Result
Last updated