Get started with NaviKit SDK

Getting started with NaviKit SDK is very similar to enabling the regular MapKit, though there are some important differences.

Step 1. Get a key for NaviKit SDK

You need an API key to work with NaviKit SDK.

  1. Get the MapKit API key.
  2. You need to activate the API key before you can use it in apps with NaviKit SDK. To do so, contact us at sales@mappable.world.

Step 2. Add the NaviKit SDK dependencies

To use all the functions of NaviKit SDK, you need to add dependency in your Podfile:

platform :ios, '13.0'

target 'NavikitDemo' do
    pod 'MappableMobile', '1.1.0-navikit'
    pod 'MMKStylingAutomotiveNavigation', '1.1.0'
    pod 'MMKStylingRoadEvents', '1.1.0'
end

Step 3. Permission to request location

NaviKit SDK for iOS requires permission to permission to access your location before it can track the current device location.

  1. Add the following field in your Info.plist file:

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your location is required for navigation</string>
    
  2. Create locationManager and request permission to access user location. For example, it could be done in your ViewController viewDidLoad() method:

    import CoreLocation
    import UIKit
    
    class MainViewController: UIViewController, CLLocationManagerDelegate {
        override func viewDidLoad() {
            super.viewDidLoad()
            locationManager.delegate = self
            locationManager.requestAlwaysAuthorization()
        }
        private let locationManager = CLLocationManager()
    }
    

Step 4. Set up MapKit SDK

Follow the steps from Step 3. Provide the API key to MapKit: install your API key, initialize MapKit, and create a View with the map.

You performed setup correctly if the map opens and the data loads successfully when you run the MapKit app.

Step 5. Note the following

MapKit stores weak references to the Listener objects passed to it. You need to store references to them in memory yourself:

Note

All Listener objects must be inherited from the NSObject class.

internal class CameraListener: NSObject, MMKMapCameraListener {
    func onCameraPositionChanged(
        with map: MMKMap?,
        cameraPosition: MMKCameraPosition,
        cameraUpdateReason: MMKCameraUpdateReason,
        finished: Bool
    ) {
        // Do something
    }
}

let cameraListener = CameraListener()

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.mapWindow.map!.addCameraListener(with: cameraListener)
}

When all the dependencies are installed, you can start using NaviKit SDK in your project.

You can learn about the general architecture of the NaviKit SDK entities in the next section.