MKPolyline 相交坐标 ios

MKPolyline Intersecting coordinates ios

请先查看这张图片

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

之间的确切交点

试试这个

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;
}