Skip to content

Transition from MRMapView to MRMapViewController iOS

DHollowellHPE edited this page Oct 27, 2026 · 1 revision

Transition from MRMapView to MRMapViewController (iOS)

MRMapView’s delegate is removed from SDK 7.0.0 version onwards. It's recommend using MRMapViewController rather than using MRMapView directly. All of the MRMapViewDelegate functions are accessible via MRMapViewController.

This can be achieved by one of the following approaches depends on your map view implementation:

1. Full screen map view

Create a subclass from MRMapViewController

class MapViewController: MRMapViewController {
    convenience init() {
        self.init(nibName:nil, bundle:nil)
        mapView.mapKey = MREditorKey(forMap: "5638404075159552", app: “5468665088573440") // Meridian Portland Office
    }
}

2. Embedded map view( In the case that you don't want to make the map full screen)

Create an instance of MRMapViewController and make it a subViewController of your custom viewController

   // Create an instance of MRMapViewController and map container view as class properties
      var mapViewContainer: UIView!
      var mapViewController: MRMapViewController!

      // Build the map view that will be embedded
        mapViewContainer = UIView()
        mapViewContainer.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(mapViewContainer)

        mapViewController = MRMapViewController(editorKey: MREditorKey(forMap: MSExampleHost.mapID(), app: MSExampleHost.appID()))
        mapViewController.view.translatesAutoresizingMaskIntoConstraints = false
        mapViewContainer.addSubview(mapViewController.view)

        // Add layout
        mapViewContainer.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        mapViewContainer.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        mapViewContainer.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        mapViewContainer.heightAnchor.constraint(equalToConstant: 400).isActive = true

        mapViewController.view.topAnchor.constraint(equalTo: mapViewContainer.topAnchor).isActive = true
        mapViewController.view.leadingAnchor.constraint(equalTo: mapViewContainer.leadingAnchor).isActive = true
        mapViewController.view.trailingAnchor.constraint(equalTo: mapViewContainer.trailingAnchor).isActive = true
        mapViewController.view.bottomAnchor.constraint(equalTo: mapViewContainer.bottomAnchor).isActive = true

3. Use MRMapViewDelegate functions

MRMapViewController implements all MRMapViewDelegate methods. Override them in your subclass to add extra MRMapViewDelegate functionality

class DelegateViewController: MRMapViewController {
    convenience init() {
        self.init(nibName:nil, bundle:nil)
        mapView.mapKey = MREditorKey(forMap: "5638404075159552" , app: “5468665088573440")
    }

 // MARK: - MRMapViewDelegate
  override func mapPickerDidPick(_ map: MRMap) {
        super.mapPickerDidPick(map)
       // Add your customization here
    }

    override func mapViewWillStartLoadingMap(_ mapView: MRMapView) {
        super.mapViewWillStartLoadingMap(mapView)
       // Add your customization here
    }
}

The Samples application packaged with the SDK has examples of the above cases.

Clone this wiki locally