This is an example of creating a simple search experience using MapsIndoors. We will create a map with a search button which leads to another view controller that handles the search and selection. Select a Location to go back to the map and show the selected Location on the map.
We will start by creating a simple search controller that handles search and selection of MapsIndoors Locations.
Declare a protocol for our Location selection with a didSelectLocation method
Define MySearchController. In this tutorial our search controller is a UIViewController that implements the protocols UISearchBarDelegate, UITableViewDelegate and UITableViewDataSource.
class MySearchController: UIViewController, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource {
Setup member variables for MySearchController:
An instance of type MPQuery
An array of MPLocation to hold your list of results
Your delegate object
A search bar view
A table view
let query = MPQuery()
var locations = [MPLocation]()
var delegate: MySearchControllerDelegate? = nil
let tableView = UITableView()
let searchBar = UISearchBar()
In viewDidLoad, wire up your view controller to the table view and search bar.
Implement the tableView:didSelectRowAt method. In this example we call the delegate method and dismiss the view controller. Delegate method will be handled by SearchMapController.
This is an example of creating a simple search experience using MapsIndoors. We will create a map with a search button which leads to another view controller that handles the search and selection. Select a Location to go back to the map and show the selected Location on the map.
We will start by creating a simple search controller that handles search and selection of MapsIndoors Locations.
Declare a protocol for our Location selection with a didSelectLocation method
Define MySearchController. In this tutorial our search controller is a UIViewController that implements the protocols UISearchBarDelegate, UITableViewDelegate and UITableViewDataSource.
class MySearchController: UIViewController, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource {
Setup member variables for MySearchController:
An instance of type MPLocationService
An instance of type MPQuery
An array of MPLocation to hold your list of results
Your delegate object
A search bar view
A table view
let locationService = MPLocationService.sharedInstance()
let query = MPQuery()
var locations:[MPLocation] = []
var delegate:MySearchControllerDelegate? = nil
let tableView = UITableView()
let searchBar = UISearchBar()
In viewDidLoad, wire up your view controller to the table view and search bar.
Implement the tableView:didSelectRowAt method. In this example we call the delegate method and dismiss the view controller. Delegate method will be handled by SearchMapController.