convertCoordinate toPointToView使用倾斜贴图返回错误结果

ara*_*aid 5 iphone mapkit mkmapview ios

我有一个覆盖在地图上的UIView,我正在两个坐标之间的屏幕空间中绘制一些图形

- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view
Run Code Online (Sandbox Code Playgroud)

问题是当地图非常放大和倾斜(类似3D)时,离屏的坐标的像素位置停止一致.有时函数会返回NaN,有时会返回正确的数字,而其他函数会跳转到屏幕的另一侧.

不知道如何更好地解释它.有没有人碰到这个?

Hit*_*esh 0

在研究过程中找到了很多解决方案。任何解决方案都可能适合您。

解决方案:1

int x =  (int) ((MAP_WIDTH/360.0) * (180 + lon));
int y =  (int) ((MAP_HEIGHT/180.0) * (90 - lat));
Run Code Online (Sandbox Code Playgroud)

解决方案:2

func addLocation(coordinate: CLLocationCoordinate2D)
    {
        // max MKMapPoint values
        let maxY = Double(267995781)
        let maxX = Double(268435456)

        let mapPoint = MKMapPointForCoordinate(coordinate)

        let normalizatePointX = CGFloat(mapPoint.x / maxX)
        let normalizatePointY = CGFloat(mapPoint.y / maxY)
        print(normalizatePointX)
        print(normalizatePointX)
    }
Run Code Online (Sandbox Code Playgroud)

解决方案:3

x = (total width of image in px) * (180 + latitude) / 360
y = (total height of image in px) * (90 - longitude) / 180
Run Code Online (Sandbox Code Playgroud)

注意:当使用负经度纬度时,请确保添加或减去负数,即 +(-92) 或 -(-35),实际上是 -92 和 +35