ios - 如何添加多个注释?

标签 ios swift mapkit mkannotation

我想在 map View 中显示多个图钉。所以我这样做:

let smth = [Smth(title: "Title 1", 
        locationName: "Street 1", 
        coordinate: CLLocationCoordinate2D(latitude: 43.2345965, longitude: 76.8907758)),
    Smth(title: "Title 2", 
        locationName: "Street 2",
        coordinate: CLLocationCoordinate2D(latitude: 43.2059723, longitude: 76.9012738))]

然后:

mapView.addAnnotation(smth)

但它显示此错误:

        Argument type '[Smth]' does not conform to expected type 'MKAnnotation'.

我该怎么办? 谢谢。

最佳答案

解决了这个问题:

mapView.addAnnotations(smth)

数组需要方法"addAnnotations",而不是"addAnnotation"

关于ios - 如何添加多个注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33767617/

相关文章:

ios - 在嵌套函数中返回 bool

ios - UIScrollView : Not filling width of container? 内嵌套的 UIStackViews

swift - 如何阻止 MapView 自动滚动?

ios - MapKit Overlays 消耗大量 CPU 资源

ios - Swift 3 - 动画序列停止时执行Segue

ios - 初始化父View的父View问题

ios - 连接到 Google Drive API 时出错(Swift 5)

ios - 从 App 打开 map 返回 Nil 作为自定义点注释的位置标题

ios - 如何快速返回 SqLite 的多行或表?

ios - 如何暂停和恢复动画 - KDCircularProgress 圆形条