SwiftUI Map 使用 MapPolyline 无法显示

参考:SwiftUI Map MapPolyline not showing

原因是没有为 Polyline 设置颜色:

1
2
MapPolyline(coordinates: deviceLocations)
.stroke(.blue, lineWidth: 2.0)

或者

1
2
3
4
5
6
7
8
9
10
11
12
struct CustomShapeStyle: ShapeStyle {
func resolve(in environment: EnvironmentValues) -> some ShapeStyle {
if environment.colorScheme == .light {
return Color.blue.blendMode(.lighten)
} else {
return Color.blue.blendMode(.darken)
}
}
}
...
MapPolyline(coordinates: deviceLocations)
.stroke(CustomShapeStyle(), lineWidth: 2.0)

SwiftUI Map 使用 MapPolyline 无法显示
https://wonderhoi.com/2025/08/26/SwiftUI-Map-使用-MapPolyline-无法显示/
作者
wonderhoi
发布于
2025年8月26日
许可协议