Show a map

Last updated:

Your environment is now fully configured, and you have the necessary Google Maps and MapsIndoors API keys. Next you will learn how to load a Google Maps map with MapsIndoors.

Show a map with MapsIndoors

Use the MPMapControl class to set up a Google map with MapsPeople venues, buildings & locations.

Create a view controller for your map and add a stored property of type MPMapControl:

class MapViewController: UIViewController {
private var mapControl:MPMapControl?
override func viewDidLoad() {

}
}

Place the following code in the viewDidLoad method in your view controller displaying the Google map.

let mapView = GMSMapView.map(withFrame: CGRect.zero)
self.view = mapView
self.mapControl = MPMapControl.init(map: mapView)

This will show a Google Map with a default map region displayed. Append the following search code to the already added code in viewDidLoad:

let query = MPQuery.init()
let filter = MPFilter.init()
query.query = "White House"
filter.take = 1
MPLocationService.sharedInstance().getLocationsUsing(query, filter: filter) { (locations, error) in
if let location = locations?.first {
self.mapControl.go(to:location)
}
}

Replace "White House" with the name of a known building in your MapsIndoors dataset. Run your iOS project. You should now see a map of a building.

Next up: Search