【问题标题】:Place annotations on a Map based on distance (meters) and bearing from current location根据距当前位置的距离(米)和方位在地图上放置注释
【发布时间】:2018-10-15 21:50:23
【问题描述】:

我正在开发一个应用程序来根据船的数量、目标时间、风向和风力来设计一个帆船比赛路线。

目前,我将所有变量存储在设备上,并将比赛委员会的起跑船固定在地图上。我找到了很多关于如何计算两个位置之间距离的信息,但找不到任何关于如何放置注释 xx 米/距起始船只的方位 xx 度的信息。

起始船只在地图上(位置:纬度/经度)。如何在距起始船 500 米处放置注释,方位角为 90 度?

【问题讨论】:

    标签: swift mapkit cllocation


    【解决方案1】:

    我相信有很多关于如何在纬度/经度位置放置注释的示例。因此,我将帮助您了解如何获取目标位置

    首先,您可以查看 Haversine 公式来获取纬度/经度位置 在Get lat/long given current point, distance and bearing有一个很好的python示例

    如果目标距离当前用户航向 500 米和 90 度,则可以使用此功能进行快速操作

       func getNewTargetCoordinate(position: CLLocationCoordinate2D, userBearing: Float, distance: Float)-> CLLocationCoordinate2D{
    
        let r = 6378140.0
        let latitude1 = position.latitude * (Double.pi/180) // change to radiant
        let longitude1 = position.longitude * (Double.pi/180)
        let brng = Double(userBearing+90) * (Double.pi/180)
    
        var latitude2 = asin(sin(latitude1)*cos(Double(distance)/r) + cos(latitude1)*sin(Double(distance)/r)*cos(brng));
        var longitude2 = longitude1 + atan2(sin(brng)*sin(Double(distance)/r)*cos(latitude1),cos(Double(distance)/r)-sin(latitude1)*sin(latitude2));
    
        latitude2 = latitude2 * (180/Double.pi)// change back to degree
        longitude2 = longitude2 * (180/Double.pi)
    
        // return target location
        return CLLocationCoordinate2DMake(latitude2, longitude2)
    }
    

    【讨论】:

    • 这正是我想要的。使用这个函数,我可以通过解析变量距离和方位来计算浮标 1、浮标 2、浮标 3 等的位置。非常感谢您的帮助!
    • 欢迎您,如果这解决了您的问题,您可以将其作为可接受的答案
    猜你喜欢
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2017-05-15
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多