无法将 CGPoint 分配给 CLLocationCoordinate2D

Cannot assign CGPoint to CLLocationCoordinate2D

var touchPoint = gestuRerecognizer.locationInView(self.map)
var newCoordinate = map.convertPoint(touchPoint, fromCoordinateSpace: self.map)
var annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate

此代码给我(无法将类型 'CGPoint' 的值分配给类型 'CLLocationCoordinate2D' 的值)错误。

应该是:

let newCoordinate = map.convertPoint(touchPoint, toCoordinateFromView:self.map)
annotation.coordinate = newCoordinate

而不是:

var newCoordinate = map.convertPoint(touchPoint, fromCoordinateSpace:self.map)

因为它返回给您的是 CGPoint,而不是 CLLocationCoordinate2D,当您将 newCoordinate 分配给 annotation.coordinate 时会导致错误。