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.
Specify the following dependency in your Carthage Cartfile:
github "mapbox/mapbox-directions-swift" ~> 2.0
Or in your CocoaPods Podfile:
pod 'MapboxDirections', '~> 2.0'
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.0.0
- To gain access to the Mapbox Directions and Map Matching APIs, set
MBXAccessTokenin your Info.plist.
MGLMapboxAccessTokenis still supported but is now deprecated. (#522)
- MapboxDirections now requires Turf v2.x. (#571, #608)
mapbox-directions-swiftcommand line tool can no longer be built using Carthage. It now requires swift-argument-parser v1.0.0 or above. (#606)
Incident.impactproperty is now an
Incident.Impactvalue instead of a string. (#519)
- Added the
Intersection.usableLaneIndicationproperties that indicate preferred lane usage.
VisualInstruction.Component.lane(indications:isUsable:)has been renamed to
- Comparing two
==now considers whether the
Intersection.outletMapboxStreetsRoadClassproperties are equal. (#529)
- Carthage v0.38 or above is now required for installing this SDK if you use Carthage. (#548)
- Xcode 12.0 or above is now required to build MapboxDirections from source. (#548)
- You can fully build this SDK on Macs with Apple Silicon. (#548)
RouteOptions.speedare now optional. Set them explicitly if you want to include them in the HTTP request. Renamed
- Removed the
DirectionsResult.routeIdentifierproperty. Use the
RouteResponse.identifierproperty in conjunction with an index into the
RouteResponse.routesarray instead. (#562)
- Fixed an issue where RouteStep.exitIndex was always unset. (#567)
- Added the
Waypoint.allowsSnappingToClosedRoadproperty to allow snapping the waypoint’s location to a closed part of a road. (#583)
NumericCongestionLevelto support receiving the numeric value for congestion level along each segment of a
- Fixed an issue where
RouteLeg.segmentRangesByStepcontained a range that was off by one for the arrival step of a leg. (#587)