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

这段代码给了我(不能将 'CGPoint' 类型的值分配给 'CLLocationCoordinate2D' 类型的值)错误。

4

1 回答 1

1

它应该是:

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

代替:

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

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

于 2015-08-19T07:27:24.903 回答