1

请先检查这张图片

在此处输入图像描述

我有一个 lat long 坐标数组,我通过它创建了一个MKPolyline现在我想找到两个 lat long 的交点坐标MKPolyline。为此,我尝试了 MKPolyLine Intersects or not 方法,但它只返回 bool 值,而不是 lat long 坐标。我也试过http://www.movable-type.co.uk/scripts/latlong.html找出两点之间的中点,但它不起作用。那么我们能否找到两者之间的确切交点MKPolyline

4

1 回答 1

3

尝试这个

CGFloat m1, c1, m2, c2;
CGFloat x11, y11, x12, y12; //line 1
CGFloat x21, y21, x22, y22; //line 2
CGFloat dx, dy;
CGFloat intersection_X, intersection_Y;


dx = x12 - x11;
dy = y12 - y11;

m1 = dy / dx;
c1 = y11 - m1 * x11; 



dx = x22 - x21;
dy = y22 - y21;

m2 = dy / dx;
c2 = y22 - m2 * x22; 


if( (m1 - m2) == 0)
{
    NSLog(@"No Intersection between the lines");
}
else
{
    intersection_X = (c2 - c1) / (m1 - m2);
    intersection_Y = m1 * intersection_X + c1;
}
于 2016-06-29T09:01:17.967 回答