【问题标题】:Calculate location by distance from other location根据与其他位置的距离计算位置
【发布时间】:2013-06-02 09:02:44
【问题描述】:

我知道关于如何获取两个 CLLocation 之间的距离有很多问题(和答案)。但是我没有找到一个关于如何反过来做的提示。

这是具体情况:我有一个 CLLocation、一个距离(比如说 200 米)和一个方向。现在我需要知道如何计算距离第一个位置 200 米(在指定方向上)的位置。我不知道方向的最佳格式是什么。也许最好的单位是度数(北 = 0,东 = 90,南 = 180,西 = 270)。

简而言之,我需要一个可以像这样定义的方法

-(CLLocation*)locationWithDistance:(int)meters inDirection:(int)degrees fromLocation:(CLLocation*)origin;

非常感谢您的帮助。

【问题讨论】:

标签: ios core-location


【解决方案1】:

要获得更准确的方法,请在链接中使用此公式

http://www.movable-type.co.uk/scripts/latlong.html

请找到“目标点距起点的距离和方位角”部分。在你的代码中应用它

【讨论】:

    【解决方案2】:

    已经编写了 C 代码来做到这一点。它发布在github here。 UtilitiesGeo.c/.h 文件中有该函数的度数和弧度版本。它可以用 Objective-C 风格编写,但我希望它可以移植到任何基于 C 的项目中。

    /*-------------------------------------------------------------------------
    * Given a starting lat/lon point on earth, distance (in meters)
    * and bearing, calculates destination coordinates lat2/lon2.
    *
    * all params in degrees
    *-------------------------------------------------------------------------*/
    void destCoordsInDegrees(double lat1, double lon1,
                             double distanceMeters, double bearing,
                             double* lat2, double* lon2);
    

    【讨论】:

      猜你喜欢
      • 2020-11-27
      • 2011-04-03
      • 1970-01-01
      • 2017-04-20
      • 1970-01-01
      • 2011-12-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多