Search
Last updated
Last updated
From here onwards, code for both Mapbox and Google Maps
is similar.
Take a look at the following code. As discussed before, this will select a location specifically named "The Crow".
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 in our ViewController class, so feel free to update it as follows.
Let us start off by implementing the search bar. In this case, we add the following variables to our ViewController
class. 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 is correctly displayed in our view and the ViewController
is its delegate.
Finally, let us add the functions necessary for our class to conform to the UISearchBarDelegate
and UITableViewDataSource
protocols for the actual search button functionality.
This responds to what the user enters in the search bar and tells MapsIndoors to search for the entered text and show the found Locations in the table view. This is almost exactly the same as the initial simple search we included in Display a Map with MapsIndoors.
These three functions simply outline the appearance of the table. Namely, how many rows to show and which text to represent each entry.
This instructs what to do once an item is selected – in this case we simply go to the specified Location and hide the table view again.
At this point we should have a functional map with a search feature.