【问题标题】:annoying parameter error for polylineWithCoordinatespolylineWithCoordinates 的恼人参数错误
【发布时间】:2015-05-17 20:25:52
【问题描述】:

我正在尝试使用以下代码从名为 coordarray 的 2 元素 CLLocationCoordinate2D 数组和数字 2 初始化折线:

self.line = MKPolyline.polylineWithCoordinates(coordarray,2)

但是我收到一个错误提示

无法使用类型参数列表调用“polylineWithCoordinates” ([CLLocationCoordinate2D],Int)

我检查了文档,似乎我传递了正确的参数列表,我缺少什么?

【问题讨论】:

    标签: ios swift mkpolyline


    【解决方案1】:

    该错误消息非常具有误导性 - 检查 MKPolyline 的文档实际上并没有一个名为 polylineWithCoordinates 的静态方法用于 Swift,您可能正在查看文档的 Objective-C 版本*。也许您打算使用:

    convenience init!(coordinates coords: UnsafeMutablePointer<CLLocationCoordinate2D>,
                      count count: Int)
    

    在这种情况下,我认为您的代码需要:

    // Note - coordarray is declared as var
    var coordarray = // ...
    
    self.line = MKPolyline(coordinates: &coordarray, count: 2)
    

    这是一个链接,详细介绍了添加 MKPolyline 叠加层的更多信息:http://mobiletoolworks.com/adding-a-mkpolyline-overlay-using-swift-to-an-ios-mapkit-map/

    *要将文档从显示 Objective-C 更改为 Swift,页面右上角有一个控件:

    【讨论】:

    • 嘿,你的链接怎么了?谢谢!
    猜你喜欢
    • 2011-05-22
    • 2011-09-02
    • 1970-01-01
    • 2013-06-05
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    相关资源
    最近更新 更多