2015-08-19 64 views
0
var touchPoint = gestuRerecognizer.locationInView(self.map) 
var newCoordinate = map.convertPoint(touchPoint, fromCoordinateSpace: self.map) 
var annotation = MKPointAnnotation() 
annotation.coordinate = newCoordinate 

此代碼給我(不能鍵入「CGPoint」的值賦給類型「CLLocationCoordinate2D」值)錯誤。無法分配CGPoint到CLLocationCoordinate2D

回答

1

它應該是:

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

相反的:

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

,因爲它返回你一個CGPoint,而不是一個CLLocationCoordinate2D,這會導致當你將newCoordinateannotation.coordinate錯誤。