MeridianAtlas for iOS
Turn-by-turn navigation in Swift: routes with lane-level guidance, spoken
announcements the SDK times for you (and an opt-in voice to say them),
rerouting, dead reckoning through tunnels, free drive with road names and speed
limits, and the Atlas 3D map (AtlasMapView) following the car.
Requirements
- iOS 15 or later (macOS 12 or later for everything except the map view)
- Xcode 16 or later
- A Meridian Atlas API key (an app key made in Atlas Studio for your bundle ID) and service URL
Install
Until the package is published, unzip the release archive
(MeridianAtlas-0.1.0-rc.6.zip) and add it in Xcode with File > Add Package
Dependencies… > Add Local…, then import MeridianAtlas.
App setup
Your app owns location permission and Core Location. In its Info.plist,
NSLocationWhenInUseUsageDescription says why it needs location. To keep
guiding with the screen locked, add the location background mode
(UIBackgroundModes; Background Modes > Location updates in Xcode), and
NSLocationAlwaysAndWhenInUseUsageDescription if you will ask for Always.
Set the location manager up for driving: desiredAccuracy = kCLLocationAccuracyBestForNavigation, activityType = .automotiveNavigation,
pausesLocationUpdatesAutomatically = false (else iOS pauses fixes in a long
queue), and allowsBackgroundLocationUpdates = true with
showsBackgroundLocationIndicator = true (only with the background mode: it
traps without it). The iOS quickstart's "App setup" has the code.
How it fits together
Your app owns location permission and Core Location. It passes each fix to
AtlasNavigation.ingest(_:) and calls tick() about once a second, so GPS
loss is noticed. Atlas sends back updates with the progress and effects to act
on. Made with a configuration, the session reroutes by itself: when the car
leaves the route it fetches a new one, facing the way the car is going and
asked the way the route was, and keeps the old route until it arrives. The app
shows the new route when route_replaced brings it (effect.route).
The network calls are the service clients and the map view, which loads the
Atlas viewer. The clients are AtlasRoutes (routes with guidance),
AtlasMultiStop (one route through several stops, in order),
AtlasRouteMatrix (distances and times between many origins and
destinations), AtlasPlaces (search, details and photos) and AtlasTraffic
(the traffic delay on a route). Each feature is turned on per API key.
final class Trip {
let routes: AtlasRoutes
private(set) var navigation: AtlasNavigation!
private let show: (AtlasRoute) -> Void
/// `show` puts a route on the map: `{ map.show($0) }`.
init(configuration: AtlasConfiguration, show: @escaping (AtlasRoute) -> Void) {
routes = AtlasRoutes(configuration: configuration)
self.show = show
// The navigation keeps its onUpdate closure, so capture self weakly: a strong
// capture would keep the trip and its navigation alive for good.
navigation = AtlasNavigation(configuration: configuration, onUpdate: { [weak self] update in self?.handle(update) })
}
func start(from origin: [Double], to destination: [Double]) async throws {
let route = try await routes.route(from: origin, to: destination)
_ = try navigation.begin(route.plan)
show(route) // route.guidance: the instructions to show and speak
}
private func handle(_ update: AtlasNavigationUpdate) {
// The session reroutes by itself: show each new route when it takes it.
for effect in update.effects where effect.type == "route_replaced" {
if let route = effect.route { show(route) }
}
}
}
let atlas = try AtlasConfiguration(apiKey: apiKey)
let map = try AtlasMapView(configuration: atlas)
let trip = Trip(configuration: atlas, show: { map.show($0) })
try await trip.start(from: [-2.2511, 53.4747], to: [-2.246, 53.4837])The configuration's service and map viewer default to https://api.meridianatlas.dev and
https://maps.meridianatlas.dev/v1. That domain isn't live yet: beta partners pass the
addresses Meridian gave them (the quickstart's "Configure the key").
Made with the configuration, the session also registers its navigation legs,
so its reroutes are included in them (up to 50 a leg). To use your own routing,
pass rerouting: .custom { effect in ... }, or .manual to answer each
request_reroute with completeReroute(requestId:route:) or
failReroute(requestId:failure:) (the iOS quickstart has the details).
Each update can carry an announcement ("In 300 yards, turn left onto
Deansgate"), timed by the session, a rerouted route's included. AtlasVoice
says it with the best installed British voice, or with your own speech, and
never touches your audio session (the quickstart's "Speaking the guidance").
AtlasCarPlay puts the map and guidance on CarPlay, the dashboard and the
instrument cluster, and AtlasRouteSimulator drives a session along a route
for testing and app review: the CarPlay and Android Auto guide (docs/sdk/car-screens.md).
Location fixes, ticks and reroute answers are synchronous: make them from one
thread. A session that reroutes by itself answers on the main thread, so use it
from the main thread. AtlasMapView can be updated from any
thread; it moves the work onto the main thread itself. Errors are AtlasError
with a code, the same on every Atlas SDK (missing_api_key,
invalid_api_key, capability_required, rate_limit, network_error,
outside_coverage, …), a message that says what to fix, and isRetryable;
AtlasError.location(manager) says whether the user has allowed precise
location. Every code is in Errors.
Licence
Copyright Meridian. All rights reserved. Use is subject to your Meridian Atlas agreement.