The Maplibre Navigation SDK for iOS is built on a fork of the Mapbox Navigation SDK v0.21 which is build on top of the Mapbox Directions API (v0.23.0) and contains logic needed to get timed navigation instructions.
With this SDK you can implement turn by turn navigation in your own iOS app while hosting your own Map tiles and Directions API.
All issues are covered with this SDK.
MaplibreNavigation version 4 allows you to start a navigation in an existing Map, so no modal ViewController needs to be presented over an existing map as before. This results in some breaking changes.
Replace your ViewController that hosts the mapView with a NavigationViewController
. We suggest to create a subclass of NavigationViewController
and override init & call super.init(dayStyle:)
or super.init(dayStyleURL:)
. With version 3, NavigationViewController will not start navigation until you request it.
Start the navigation by calling startNavigation(with: route)
. If you want to simulate your route, you need to pass in the optional locationManager parameter, otherwise the real location of the device will be used.
#if targetEnvironment(simulator)
let locationManager = SimulatedLocationManager(route: route)
locationManager.speedMultiplier = 2
self.startNavigation(with: route, animated: false, locationManager: locationManager)
#else
self.startNavigation(with: route, animated: false)
#endif
Make your ViewController conform to NavigationViewControllerDelegate
and implement navigationViewControllerDidFinishRouting(_ navigationViewController: NavigationViewController)
to transition back to normal map mode. This delegate is called when the user arrives at the destination or cancels the navigation.
extension SceneDelegate: NavigationViewControllerDelegate {
func navigationViewControllerDidFinishRouting(_ navigationViewController: NavigationViewController) {
navigationViewController.endNavigation()
}
}
NOTE: You've probably used this function previously, it was removed as we don't dismiss a ViewController anymore.
@objc optional func navigationViewControllerDidDismiss(_ navigationViewController: NavigationViewController, byCanceling canceled: Bool)
If you want to keep the old way of presenting a navigation modally, you can still do that. Simply call startNavigation(with: route)
right after creating the NavigationViewController
.
If you are looking to include this inside your project, you have to follow the the following steps:
Install this package using the Swift Package Manager.
Info.plist
arm64
to PROJECT -> <Project naam> -> Build Settings -> Excluded Architecture Only
We do provide a limited example app but its not functional right out of the box.
Join the #maplibre-native Slack channel at OSMUS: get an invite at https://slack.openstreetmap.us/ Read the CONTRIBUTING.md guide in order to get familiar with how we do things around here.
Code is licensed under MIT and ISC. ISC is meant to be functionally equivalent to the MIT license.
Copyright (c) 2022 MapLibre contributors