swift - Mapbox MGLAnnotations 未在 MapView for Mapbox iOS 上呈现
问题描述
我一直在为我的 SwiftUI 应用程序使用 MapBox 进行测试,但我遇到了我的注释没有出现在我的 MapView 上的问题,即使它们似乎已经添加了。我在 updateUIView 上调用的 updateAnnotations 命令的代码是:
private func updateAnnotations() {
if let currentAnnotations = mapView.annotations {
mapView.removeAnnotations(currentAnnotations)
}
for marker in devices.positions {
let annotation = MGLPointAnnotation(title: marker.name, coordinate: marker.coordinate)
mapView.addAnnotation(annotation)
print("ADDED \(annotation)")
print(mapView.annotations)
}
}
devices
是一个 @ObservedObject ,其中包含一个positions
点数组,其中包含要绘制的标题和坐标。我从这段代码的输出是:
ADDED <MGLPointAnnotation: 0x285abc9f0; title = "Test"; subtitle = (null); coordinate = -36.892800, 174.625000>
Optional([<MGLPointAnnotation: 0x2866b7c60; title = "Test"; subtitle = (null); coordinate = -36.892800, 174.625000>])
这对我来说没有意义 - 输出表明注释已创建,但它没有显示在地图上。任何帮助将不胜感激。
解决方案
使用 SwiftUI 时需要传入 MapView - 例如更改updateAnnotations()
为updateAnnotations(_ mapView: MGLMapView)
推荐阅读
- spring - 如何使用 okhttp MockWebServer 模拟 Mockito 之类的 bean
- laravel - Dusk + Stripe = 无法定位元素
- sql - 查询中的 Listagg 具有别名
- java - 春季安全工作仅适用于最高优先级订单
- java - 如何在不同进程中使用 LocalBroadcastManager 在 Activity 和 Service 之间进行通信
- flutter - Flutter Stream Builder - 流获取 null
- html - 如何从 2 段创建堆叠图片?
- julia - 什么是 Julia 相当于 numpy 的 where 函数?
- python - 熊猫组然后申请抛出警告
- sql - 如何仅使用数据提取值但仅填充一组字段