使用XCode v7.0 Beta 4
我尝试通过map. addannotation (myareahere)为该地图添加一个可见的pin,如图所示:
let myareahere = CLLocationCoordinate2DMake(51.5072, -0.1275)
let annotation = MKPointAnnotation()
annotation.coordinate = myareahere
annotation.title = "Name of My Area"
annotation.subtitle = "Sleep Here"
map.addAnnotation(myareahere)
这些当然都包含在viewDidLoad函数中。我在最后一行给出的错误(map.addAnnotation(myareahere))是"不能用列表类型的参数(CLLocationCoordinates2D)调用'addAnnotation'"。这让我很困惑,因为我不知道我还能用什么。
错误告诉您使用错误的参数类型调用addAnnotation(_:)
。您正在传递一个CLLocationCoordinate2D
到方法,您的意思是传递annotation
(您的MKPointAnnotation
实例)。
似乎是一个简单的打字错误。试着
let annotation = MKPointAnnotation()
annotation.coordinate = myareahere
annotation.title = "Name of My Area"
annotation.subtitle = "Sleep Here"
map.addAnnotation(annotation)
.