var touchPoint = gestuRerecognizer.locationInView(self.map)
var newCoordinate = map.convertPoint(touchPoint, fromCoordinateSpace: self.map)
var annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate
此代码使我(无法将类型'CGPoint'的值分配给'CLLocationCoordinate2D'类型的值)错误。
答案 0 :(得分:1)
应该是:
let newCoordinate = map.convertPoint(touchPoint, toCoordinateFromView:self.map)
annotation.coordinate = newCoordinate
而不是:
var newCoordinate = map.convertPoint(touchPoint, fromCoordinateSpace:self.map)
因为它会向您返回CGPoint
,而不是CLLocationCoordinate2D
,这会在您将newCoordinate
分配给annotation.coordinate
时导致错误。