【问题标题】:Error "Missing argument for parameter 'coordinate' in call"错误“调用中的参数‘坐标’缺少参数”
【发布时间】:2016-08-03 10:01:10
【问题描述】:

我有一个自定义的 MkAnnotation,它有一个标题、副标题和与之关联的额外信息,用于地图视图。我将此信息传递给另一个 UIViewController。但是,我为引脚分配的坐标似乎存在一些问题。错误在下面代码“var bridge17pin = MyAnnotation()”行的pin设置信息中突出显示。

   override func viewDidLoad() {
    super.viewDidLoad()

    //for users location
    myLocMgr.desiredAccuracy = kCLLocationAccuracyBest
    myLocMgr.requestWhenInUseAuthorization()
    myLocMgr.startUpdatingLocation()
    myLocMgr.delegate = self
    mapView.delegate = self



 //coordinate for pin
 var bridge17 = CLLocationCoordinate2DMake(53.346061, -6.227379)


       //custom MKAnnotation
       class MyAnnotation: NSObject, MKAnnotation {
        @objc var coordinate: CLLocationCoordinate2D
        var EXTRA_INFORMATION: String?
        var title: String?

        init(coordinate: CLLocationCoordinate2D) {
           self.coordinate = coordinate
        }
    }



    //setting information of pin
    var bridge17pin = MyAnnotation()
    bridge17pin.coordinate = bridge17
    bridge17pin.title = "The bridge"
    bridge17pin.subtitle = "hello this is the bridge"
    bridge17pin.EXTRA_INFORMATION = "this was built in 2010"
    mapView.addAnnotation(bridge17pin)
      }

【问题讨论】:

    标签: annotations mapkit mkannotation mkpinannotationview cllocationcoordinate2d


    【解决方案1】:

    因为您必须在实例化时发送坐标。所以在代码中替换

    var bridge17pin = MyAnnotation()
    

    var bridge17pin = MyAnnotation(coordinate: bridge17)
    

    对于那个子标题see this link

    【讨论】:

      猜你喜欢
      • 2019-11-25
      • 2021-10-02
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      相关资源
      最近更新 更多