【问题标题】:Get point coordinate on a MKCircle radius获取 MKCircle 半径上的点坐标
【发布时间】:2020-03-12 19:46:54
【问题描述】:

我在另一个主题中找到了我的问题的答案,并根据我的需要更改了功能。但我没有达到预期的结果。 我用这个函数,我想得到半径上的点。

   func radiusSearchPoint(coordinate: CLLocationCoordinate2D, radius: CLLocationDistance) -> CLLocationCoordinate2D {

    let earthRadius = 6_378_100.0
    let π = Double.pi
    let lat = coordinate.latitude * π / 180.0
    let lng = coordinate.longitude * π / 180.0

    let t: Double = 0

    let pointLat = lat + (radius / Double(earthRadius)) * sin(t)
    let pointLng = lng + (radius / Double(earthRadius)) * cos(t)
    let point = CLLocationCoordinate2D(latitude: pointLat * 180 / π, longitude: pointLng * 180 / π)

    return point
}

Red line consists of two points: center of circle and the point that was received after the function was executed, but second point should be on the circle

我怎样才能在圆的半径上正确地得到这个点?

【问题讨论】:

    标签: ios swift mkcircle


    【解决方案1】:

    欢迎来到stackoverflow。检查你的函数值,在我看来红线应该在圆圈内结束(而不是在圆圈上)。

    您遇到的问题是用于计算经度角度的半径随纬度而变化。随着纬度角的增加,您可以定义越来越小的恒定纬度圆圈。纬度圆的半径为 R * cos(lat)。其中R是地球的半径。将pointLng 更改为:

    let pointLng = lng + (radius / Double(earthRadius * cos(lat))) * cos(t)
    

    还值得一提的是,地球不是一个球体,所以这个计算会出错,在两极附近会变得更糟。要准确地执行此操作,您需要转换为 ECEF 坐标以获得准确的半径值,然后再返回 WGS84(纬度、经度)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多