【问题标题】:Calculate coordinate by distance from another coordinate通过与另一个坐标的距离计算坐标
【发布时间】:2014-05-23 07:13:12
【问题描述】:

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

已知参数:
Point1 = [lat1,lon1],
Point2 = [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 米。

【问题讨论】:

  • 我认为答案是使用勾股定理,它可能是平坦的表面和非常短的距离。对于曲面和更适合较大距离的计算,请尝试以下答案:stackoverflow.com/a/6634982/467105

标签: ios objective-c


【解决方案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)

【讨论】:

  • 非常感谢。我想我理解逻辑。但是你能解释一下,为什么 result.y = Point2.x +... 而不是 Point1.x +... ?
【解决方案2】:

不久前我写了一篇详细的博客,其中解释了进行此计算的两种不同方法以及它们背后的数学证明。一种方法是使用余弦定律计算弧长,另一种方法是使用Haversine 公式。你可以在这里找到博客:http://rbrundritt.wordpress.com/2008/10/14/calculate-distance-between-two-coordinates/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2016-11-06
    • 2020-01-19
    相关资源
    最近更新 更多