Ios Swift:如何将CGPoint转换为CLLocationCoordinate2D
我有下面的代码,正在尝试为地图上的长按添加注释。locationInView的类型为“CGPoint”,而“annotation.coordinate”的变量类型应为CLLocationCoordinate2D。 将CGPoint转换为CLLocationCoordinate2D的正确方法是什么Ios Swift:如何将CGPoint转换为CLLocationCoordinate2D,ios,swift,Ios,Swift,我有下面的代码,正在尝试为地图上的长按添加注释。locationInView的类型为“CGPoint”,而“annotation.coordinate”的变量类型应为CLLocationCoordinate2D。 将CGPoint转换为CLLocationCoordinate2D的正确方法是什么 func myGestureFunc(thegesture: UIGestureRecognizer) { let pointOfInterest = thegesture.loca
func myGestureFunc(thegesture: UIGestureRecognizer) {
let pointOfInterest = thegesture.locationInView(self.theMap) //CGPoint
let annotation = MKPointAnnotation()
annotation.coordinate = //expects CLLocationCoordinate2D
theMap.addAnnotation(annotation)
}
您应该使用
convertPoint
,其内容如下:
let touchPoint = thegesture.locationInView(self.theMap)
let newCoordinate = self.theMap.convertPoint(touchPoint, toCoordinateFromView:self.theMap)
let annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate
theMap.addAnnotation(annotation)
由于convertPoint()方法不再可用,因此可以使用以下代码:
let coordinate = googleMapView.projection.coordinate(for: point)
在谷歌地图sdk中没有更多返回坐标的选项,它总是返回cgpoint/cgrect在这种情况下我应该怎么做。