Mapbox Directions for Swift
Mapbox Directions for Swift makes it easy to connect your iOS, macOS, tvOS, or watchOS application to the Mapbox Directions and Map Matching APIs. Quickly get driving, cycling, or walking directions, whether the trip is nonstop or it has multiple stopping points, all using a simple interface reminiscent of MapKit’s
MKDirections API. Fit a GPX trace to the OpenStreetMap road network. The Mapbox Directions and Map Matching APIs are powered by the OSRM and Valhalla routing engines. For more information, see the Mapbox Navigation homepage.
Mapbox Directions pairs well with MapboxGeocoder.swift, MapboxStatic.swift, the Mapbox Navigation SDK for iOS, and the Mapbox Maps SDK for iOS or macOS SDK.
Specify the following dependency in your Carthage Cartfile:
github "mapbox/mapbox-directions-swift" ~> 2.9
Or in your CocoaPods Podfile:
pod 'MapboxDirections', '~> 2.9'
Or in your Swift Package Manager Package.swift:
.package(url: "https://github.com/mapbox/mapbox-directions-swift.git", from: "0.30.0")
You’ll need a Mapbox access token in order to use the API. If you’re already using the Mapbox Maps SDK for iOS or macOS SDK, Mapbox Directions automatically recognizes your access token, as long as you’ve placed it in the
MBXAccessToken key of your application’s Info.plist file.
Directions is the main class that represents the Mapbox Directions and Map Matching APIs. To calculate directions between coordinates, configure a
RouteOptions object and pass it into
Directions.calculate(_:completionHandler:). Similarly, to match a trace to the road network, configure a
MatchOptions object and pass it into either
Directions.calculateRoutes(matching:completionHandler:). These methods asynchronously send requests to the API, then form
Match objects that correspond to the API’s response.
Route object is composed of one or more
RouteLegs between waypoints, which in turn are composed of one or more
RouteSteps between maneuvers. Depending on the request, a
RouteStep may additionally contain objects representing intersection- and segment-level data. A
Match object is structured similarly, except that it provides additional details about how the trace matches the road network.
For further details, consult the guides and examples included with this API reference. To integrate real-time turn-by-turn navigation into your iOS application, see “Navigation SDK”. If you have any questions, please see our help page. We welcome your bug reports, feature requests, and contributions.
Changes in version 2.9.1
- This library now requires a minimum deployment target of iOS 12.0 or above, macOS 10.14.0 or above, tvOS 12.0 or above, or watchOS 5.0 or above. Older operating system versions are no longer supported. (#736)
- Added the
Waypoint.layerproperty, which can ensure that the route begins on the correct road if it is above or below another road. (#745)
- Added the
AttributeOptions.customOptionsByRawValueproperty for specifying attribute options that are still marked as beta in the Mapbox Directions API. (#748)
- Fixed stale
Incident.shapeIndexRangevalues even after calling the
- Added the
RouteLeg.closuresproperty containing information about road closures based on live traffic conditions. This information requires adding
RouteOptions.attributeOptionsproperty and setting the
- Added the
Route.refresh(from:refreshParameters:)method as a single entry point for refreshing various parameters of the