Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:如何将CGPoint转换为CLLocationCoordinate2D_Ios_Swift - Fatal编程技术网

Ios Swift:如何将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

我有下面的代码,正在尝试为地图上的长按添加注释。locationInView的类型为“CGPoint”,而“annotation.coordinate”的变量类型应为CLLocationCoordinate2D。 将CGPoint转换为CLLocationCoordinate2D的正确方法是什么

 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在这种情况下我应该怎么做。