【问题标题】:Objective-C Degree of pin in regard to user's locationObjective-C 与用户位置相关的 pin 度数
【发布时间】:2014-03-26 16:41:54
【问题描述】:

我正在尝试计算引脚与用户位置的关系。因此,如果引脚位于用户位置的正下方,则为 180 度。直接向右是 90。在 154 度之间可能有一个。 0 度是用户位置以北的 0 度。正南是 180 度。

我一直无法计算这个,我想知道这是否可能?任何想法将不胜感激!

【问题讨论】:

  • 有可能,你试过什么。您可以通过假设/警告简化为三角问题...
  • 当然有可能。基本上你在问:给定两个坐标,从一个到另一个的指南针方位是多少?当然这有点棘手,因为世界是圆的,但显然它可以做到,否则一个人将无法找到自己的出路。你试过什么?

标签: ios objective-c mkmapview mapkit


【解决方案1】:

假设您有两个点,均由纬度和经度或 X、Y 组成。假设用户面向北方,可以按如下方式完成:

//Make sure you import math.h

CGPoint currentLocation = CGPointMake(100.2, 55.53);
CGPoint pin = CGPointMake(125.54, 40.23);

//Shift the 2D space to have the currentLocation as the origin
pin.x -= currentLocation.x;
pin.y -= currentLocation.y;

//Calculate the inverse tangent (in radians)
float rad = atan(pin.y/pin.x);

//Convert the radians to degrees
float deg = rad * 180/M_PI;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多