如图所示,如何计算距离点d远离点1(具有lat1和lon1坐标)的点(x,y)的位置

已知参数:
点1 = [lat1,lon1],
点2 = [lat2,lon2],
距离= d,(以米为单位)
角度=α= atan((lat2-lat1)/(lon2-lon1))

需要找到:
目标点:x和y值。

一句话,我需要反之亦然

CLLocation *location1;
CLLocation *location2;
double distance =  [location1 distanceFromLocation:location2];

例如根据给定的距离和角度计算location2。

我尝试过的
double lat = location1.coordinate.latitude + distance * sin(alpha);
double lon = location1.coordinate.longitude + distance * cos(alpha);

但是这些值是错误的,因为1个纬度和1个经度不等于1米。

最佳答案

    CLLocation Point1;
    CLLocation Point2;
    float targetDistance;

    float length = sqrt((Point1.x-Point2.x)*(Point1.x-Point2.x) + (Point1.y-Point2.y)*(Point1.y-Point2.y));

    CLLocation result;
    result.x = Point1.x + (Point2.x-Point1.x)*(targetDistance/length);
    result.y = Point1.y + (Point2.y-Point1.y)*(targetDistance/length);

或者换句话说Point1 + normalized(Point2-Point1)*targetDistance
由于您有角度,因此您也可以:
Point1 + (cos(angle)*targetDistance, sin(angle)*targetDistance)

10-06 09:22