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.
- Get the MapKit API key.
- 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 enable multiple dependencies:
-
Add NaviKit SDK in
pubspec.yaml
file:dependencies: mappable_maps_navikit: version: ^1.1.0
-
After that, add platform libraries where NavigationStyleProvider and RoadEventsStyleProvider are implemented with UI elements and road events layer icons in the signature style of Maps API, respectively:
For Android, add dependencies in
./android/app/build.gradle
:implementation 'com.mappable.mapkit.styling:automotivenavigation:1.1.0' implementation 'com.mappable.mapkit.styling:roadevents:1.1.0'
For iOS, add dependencies in
./ios/Podflie
:platform :ios, '13.0' target 'Runner' do pod 'YMKStylingAutomotiveNavigation', '1.1.0' pod 'YMKStylingRoadEvents', '1.1.0' end
-
Run
pub get
to sync the project and apply the changes.
Step 3. Permission to request location
NaviKit SDK requires permission to request location on both Android and iOS
-
Declare permission to use locations in the Android Manifest located in
./android/app/main
:<manifest ... > <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> </manifest>
-
To declare permission to use location in iOS, find a section of code at the end of the
./ios/Podfile
that contains the information:post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) ...
Then add permission to use location there so that this section of code looks like this:
post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ '$(inherited)', ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse] 'PERMISSION_LOCATION=1', ] end end end
After this, add the following information to
./ios/Runner/Info.plist
:<key>NSLocationWhenInUseUsageDescription</key> <string>Your location is required for navigation</string>
-
Request the user's permission to access their location while the app is running. This can be done, for example, using the permission_handler package.
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:
final class MapCameraListenerImpl implements MapCameraListener {
// ......
}
final class SomeMapScopedClass {
final MapWindow _mapWindow;
final MapCameraListener _cameraListener = MapCameraListenerImpl();
SomeMapScopedClass(this._mapWindow);
void addListener() {
_mapWindow.map.addCameraListener(_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.