MapKit offers showsTraffic: Bool, which is great for displaying live traffic data on the map. However, MapPolyline sits above it, which makes it quite useless. Is this the expected behaviour?
SwiftUI MapKit
Use the .mapOverlayLevel(level:) modifier on your MapContent to position polylines relative to other map elements. Setting .aboveRoads places polylines above roads but below labels and traffic, keeping traffic data visible. Setting .aboveLabels places them above everything including traffic.
Negative
.aboveRoads still won't place the MapPolyline below the traffic layer.
There's no public API to insert a polyline between road geometry and road labels. That middle layer is what Apple Maps appears to use internally for its own route rendering, but it's private and not accessible to us...
Apple Maps achieves (I guess) that look purely because it has access to an internal rendering pipeline that isn't exposed through MapKit's public APIs
Tested with a simple snippet and confirmed in the same location (next to my house)
Map(position: $cameraPosition) {
UserAnnotation()
if let route {
MapPolyline(route.polyline)
.stroke(.blue, style: StrokeStyle(lineWidth: 8, lineCap: .round))
.mapOverlayLevel(level: .aboveRoads)
}
}
.mapStyle(.standard(
elevation: .automatic,
emphasis: .automatic,
pointsOfInterest: .all,
showsTraffic: true
))