无法将CGPoint分配给CLLocationCoordinate2D

时间:2015-08-19 07:15:06

标签: ios swift2

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

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

1 个答案:

答案 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时导致错误。