gpt4 book ai didi

iphone - 将 CLLocation 移动 x 米

转载 作者:行者123 更新时间:2023-12-03 18:17:04 24 4
gpt4 key购买 nike

我定义了一个 CLLocation,我想将该点向东移动 x 米,向南移动 y 米。我怎样才能实现这一目标?

最佳答案

到 Swift 的转换,取自 this answer :

func locationWithBearing(bearingRadians:Double, distanceMeters:Double, origin:CLLocationCoordinate2D) -> CLLocationCoordinate2D {
let distRadians = distanceMeters / (6372797.6) // earth radius in meters

let lat1 = origin.latitude * M_PI / 180
let lon1 = origin.longitude * M_PI / 180

let lat2 = asin(sin(lat1) * cos(distRadians) + cos(lat1) * sin(distRadians) * cos(bearingRadians))
let lon2 = lon1 + atan2(sin(bearingRadians) * sin(distRadians) * cos(lat1), cos(distRadians) - sin(lat1) * sin(lat2))

return CLLocationCoordinate2D(latitude: lat2 * 180 / M_PI, longitude: lon2 * 180 / M_PI)
}

Morgan Chen wrote this:

All of the math in this method is done in radians. At the start of themethod, lon1 and lat1 are converted to radians for this purpose aswell. Bearing is in radians too. Keep in mind this method takes intoaccount the curvature of the Earth, which you don't really need to dofor small distances.

我的评论(2021 年 3 月 25 日):

这种方法中使用的计算称为求解“直接测地线问题”,这在 C.F.F. 中进行了讨论。 Karney 的文章“Algorithms for geodesics”,2012 年。上面给出的代码使用的技术不如 Karney 文章中介绍的算法准确。

关于iphone - 将 CLLocation 移动 x 米,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7278094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com