ios - 无法将 CGPoint 分配给 CLLocationCooperative2D

标签 ios swift swift2 cllocation 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 分配给 注释时导致错误。坐标.

关于ios - 无法将 CGPoint 分配给 CLLocationCooperative2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32088828/

相关文章:

ios - UIAlertView 未返回适当的值

ios - UIToolBar 在 3.5 英寸模拟器中不显示

ios - 如何在spritekit中录制游戏场景

ios - 尝试从类对象数组中读取值时得到 "fatal error: NSArray element failed to match the Swift Array Element type"

ios - 从 View Controller 转到 TableView 的下一个单元格

ios - 附加数据库时出错不是错误的 sqlite 数据库

ios - 如何使用 Swift 将自定义上下文菜单项添加到 UITextView?

iOS 11 安全区域布局指南向后兼容

ios - swift UIGraphicsGetImageFromCurrentImageContext 无法释放内存

ios - Xcode 添加 objective-c 文件 "file type"