我有一个自定义的MkAnnotation,它有一个标题、副标题和与之相关的额外信息,以便在地图视图上使用。我正在将此信息传递给另一个UIViewController。然而,我为引脚分配的坐标似乎有一些问题。该错误在下面代码行"var bridge17pin = MyAnnotation()“上的引脚设置信息中突出显示。
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)
}发布于 2016-08-03 18:28:55
因为您必须在实例化时发送坐标。因此,在代码中替换
var bridge17pin = MyAnnotation()使用
var bridge17pin = MyAnnotation(coordinate: bridge17)对于那个subTitle see this link
https://stackoverflow.com/questions/38740381
复制相似问题