[英]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
This code gives me ( Cannot assign a value of type 'CGPoint' to a value of type 'CLLocationCoordinate2D' ) error. 这段代码给我( 无法将'CGPoint'类型的值分配给'CLLocationCoordinate2D'类型的值 )错误。
It should be: 它应该是:
let newCoordinate = map.convertPoint(touchPoint, toCoordinateFromView:self.map)
annotation.coordinate = newCoordinate
Instead of: 代替:
var newCoordinate = map.convertPoint(touchPoint, fromCoordinateSpace:self.map)
because it is returning you a CGPoint
, not a CLLocationCoordinate2D
, which causes the error when you assign newCoordinate
to annotation.coordinate
. 因为它返回你一个
CGPoint
,不是CLLocationCoordinate2D
,当你将它导致错误newCoordinate
到annotation.coordinate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.