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
分配给 注释时导致错误。坐标
.
关于ios - 无法将 CGPoint 分配给 CLLocationCooperative2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088828/