@IBAction func drop(sender: AnyObject)
{
let mapAnnotation = MKPointAnnotation()
mapAnnotation.coordinate = locationManager // Cannot assign value of type 'CLLocationManager' to type 'CLLocationCoordinate2D'
mapAnnotation.title = "If you want a title"
mapAnnotation.subtitle = "or subtitle"
myMap.addAnnotation(mapAnnotation)
}
最佳答案
如错误所述,您不能将 CLLocationManager
对象分配给 CLLocationCoordinate2D
类型的属性。
您需要将代码更改为:
mapAnnotation.coordinate = locationManager.location!.coordinate
由于各种原因,location
属性可能为nil
,强制解包会导致崩溃。所以最好使用安全解包:
if let loc = locationManager.location
{
mapAnnotation.coordinate = loc.coordinate
}
引用资料:
关于ios - 我试图放下别针,但出现此错误 : Cannot assign value of type 'CLLocationManager' to type 'CLLocationCoordinate2D' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37622089/