Swift2 来自mkCoordinateFormAppPoint的意外结果

Swift2 来自mkCoordinateFormAppPoint的意外结果,swift2,Swift2,在下面的代码片段中,我从调用mkCoordinateFormAppPoint得到了意想不到的结果 let firstPoint = MKPointAnnotation() let firstPointLocation = MKMapPointMake(41.8735923, -87.6764638) print("firstPointLocation: \(firstPointLocation)") // Prints: firstPointLocation: MKMapPoint(x: 41

在下面的代码片段中,我从调用mkCoordinateFormAppPoint得到了意想不到的结果

let firstPoint = MKPointAnnotation()
let firstPointLocation = MKMapPointMake(41.8735923, -87.6764638) 
print("firstPointLocation: \(firstPointLocation)")
// Prints: firstPointLocation: MKMapPoint(x: 41.8735923, y:-87.6764638)
let firstPointCoordinates = MKCoordinateForMapPoint(firstPointLocation)
print("firstPointCoordinates: \(firstPointCoordinates)") 
// Prints: firstPointCoordinates: CLLocationCoordinate2D(latitude: 85.0511389233241, longitude: -179.999943843137)
firstPoint.coordinate = firstPointCoordinates
print("firstPoint.coordinate: \(firstPoint.coordinate)")
// Prints: firstPoint.coordinate: CLLocationCoordinate2D(latitude: 85.0511389233241, longitude: -179.999943843137)
firstPoint.title = "Cook County Hospital"
mapView.addAnnotation(firstPoint)
从上面第二条print语句的输出中可以看到,对mkCoordinateFormAppPoint的调用将坐标转换为其他坐标。因此,该点不会出现在预期的位置。如果将mkCoordinateFormAppPoint线替换为下面的线,则该点将正确显示

firstPoint.coordinate = CLLocationCoordinate2D(latitude: 41.8735923, longitude: -87.6764638)
print("firstPoint.coordinate: \(firstPoint.coordinate)") 
// Prints: firstPoint.coordinate: CLLocationCoordinate2D(latitude: 41.8735923, longitude: -87.6764638)
我检查了mkCoordinateFormAppPoint的引用,它应该接受MKMapPoint类型并将其转换为CLLocationCoordinate2D类型:

func MKCoordinateForMapPoint(_ mapPoint: MKMapPoint) -> CLLocationCoordinate2D

你知道为什么我在这里没有得到想要的结果吗?

代码正在做它应该做的事情,但是你误用了
MKMapPointMake

MKMapPointMake从CGPoint(相对于其帧)而不是从lat/lng创建点


我认为问题的根源仅仅是困惑,或者是愚蠢的胡闹。考虑重新命名变量,使它们不太相似。如果想要将屏幕上的CG点转换成LAT/LNG.HH,则

MKMeCaseTMART是有用的。当我在查看此方法的引用时,没有对CGPoint的引用。根据他们的说法,它接受MKMapPoint类型并返回CLLocationCoordinate2D类型。此外,MKMapPoint被定义为具有两种双重类型的结构。甚至没有提到CGPoint。对不起,我使用CGPoint试图传达X和Y值与MKMapView的边界有关。假设您需要地图原点的lat/lng,您可以执行
MKMapPointMake(0,0)
然后使用
MKCoordinateForMapPoint
Casey对其进行转换,非常感谢您的帮助