SwiftUI中如何移除MKLookAroundView的道路与国家标签?
解决SwiftUI中MKLookAroundViewController移除街道标签的问题
你尝试的showsRoadLabels属性并不适用于MKLookAroundViewController,这个属性是针对MKMapViewController设计的。要隐藏LookAround视图里的街道名称及各类标签,需要通过配置MKLookAroundSceneRequest的mapConfiguration来实现。
具体实现步骤:
- 创建
MKMapConfiguration实例,关闭交通显示、排除所有兴趣点,并通过样式设置隐藏标签 - 在请求LookAround场景时传入该配置
- 将获取到的场景赋值给
MKLookAroundViewController
修改后的代码示例:
func makeUIViewController(context: Context) -> MKLookAroundViewController { let lookAroundViewController = MKLookAroundViewController() lookAroundViewController.isNavigationEnabled = true lookAroundViewController.badgePosition = .bottomTrailing // 配置地图样式以隐藏标签 let mapConfig = MKMapConfiguration() mapConfig.showsTraffic = false mapConfig.pointOfInterestFilter = .excludingAll // 使用标准样式并关闭标签显示(iOS 16.0+ 支持) mapConfig.style = .standard(elevation: .realistic, emphasis: .muted, showsLabels: false) // 处理场景请求与赋值 if let coordinate = initialScene?.coordinate { let sceneRequest = MKLookAroundSceneRequest(coordinate: coordinate) sceneRequest.configuration = mapConfig Task { do { let scene = try await sceneRequest.scene lookAroundViewController.scene = scene } catch { print("获取LookAround场景失败:\(error)") } } } else if let initialScene = initialScene { // 若已有初始场景,重新创建带配置的场景实例 let updatedScene = MKLookAroundScene(coordinate: initialScene.coordinate, radius: initialScene.radius, configuration: mapConfig) lookAroundViewController.scene = updatedScene } return lookAroundViewController }
注意事项:
showsLabels参数仅在iOS 16.0及以上版本可用,请确保项目部署目标版本符合要求- 已创建的
MKLookAroundScene实例配置无法直接修改,需重新创建带配置的实例替换原场景
内容的提问来源于stack exchange,提问作者Vincent Wackler
相关产品推荐
相关产品推荐

