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

The MPMapControl class is used to set up a Google map with MapsPeople venues, buildings & locations.

Create a view controller (or reuse the ViewController in a new project) for your map, include the libraries necessary for MapsIndors and add a stored property of type MPMapControl:

import GoogleMaps
import MapsIndoors

class MapViewController: UIViewController {
private var mapControl:MPMapControl?

override func viewDidLoad() {
}
}

MPMapControl is an addition to the Google map to show MapsIndoors content.

Place the following code in the viewDidLoad method in your view controller for displaying the Google map and initialize the MapsIndoors controller with the Google map.

let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: GMSCameraPosition())
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 below 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)
}
}

You can 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