Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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 convertCoordinate toPointToView使用倾斜贴图返回错误结果_Ios_Iphone_Mkmapview_Mapkit - Fatal编程技术网

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

Ios convertCoordinate toPointToView使用倾斜贴图返回错误结果,ios,iphone,mkmapview,mapkit,Ios,Iphone,Mkmapview,Mapkit,我在地图上叠加了一个UIView,我正在屏幕空间中使用 - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view 问题是,当地图被放大和倾斜(类似3D)时,远离屏幕的坐标的像素位置不再一致。有时该函数返回NaN,有时返回正确的数字,有时则跳转到屏幕的另一侧 我不知道怎样才能更好地解释它。有人遇到过这个问题吗?在研究过程中,我们找到了许多解决方案。任何解决方案都可能对您

我在地图上叠加了一个UIView,我正在屏幕空间中使用

- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view
问题是,当地图被放大和倾斜(类似3D)时,远离屏幕的坐标的像素位置不再一致。有时该函数返回NaN,有时返回正确的数字,有时则跳转到屏幕的另一侧


我不知道怎样才能更好地解释它。有人遇到过这个问题吗?

在研究过程中,我们找到了许多解决方案。任何解决方案都可能对您有效

解决方案:1

int x =  (int) ((MAP_WIDTH/360.0) * (180 + lon));
int y =  (int) ((MAP_HEIGHT/180.0) * (90 - lat));
解决方案: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)
    }
解决方案:3

x = (total width of image in px) * (180 + latitude) / 360
y = (total height of image in px) * (90 - longitude) / 180
注:使用负经度纬度时,请确保加上或减去负数,即+(-92)或-(-35),实际为-92和+35