My intention is to display a SwiftUI.Map (doc) with a line (that would represent a route) using MapPolyline (see doc). Unfortunately, the line does not display on neither the simulator nor a physical device. Here’s my code.
let deviceLocations = [
// note: coordinates have be obfuscated for privacy reasons
CLLocationCoordinate2D(latitude: 54.1234, longitude: -83.1234),
CLLocationCoordinate2D(latitude: 54.1235, longitude: -83.1235),
... // there a more points in my hard-coded array, but you get the idea...
]
var body: some View {
Map(initialPosition: .userLocation(fallback: .automatic),
bounds: nil,
interactionModes: .all) {
MapPolyline(coordinates: deviceLocations)
.stroke(lineWidth: 2.0)
}
.mapControlVisibility(.hidden)
}
That’s it. The simulator location is set to “Custom Location” with one of the coordinate from the list. That View is part of a view with other elements on it, but are not shown here (within a ZStack).
I don’t know what I’m missing, and the documentation does not address this deeply enough.




