【问题标题】:Programmatically move in the direction camera is facing以编程方式沿相机面对的方向移动
【发布时间】:2019-05-26 14:36:29
【问题描述】:

我正在尝试将用户位置标记沿相机朝向的方向移动。有点像你会在游戏中控制一个角色。 由于 MapKit 中的相机是向北对齐的,我想为了向前移动,我会添加一些纬度,然后在相机角度上旋转结果点。

我有一些从米到多少度的转换器:

class Converter {
  fileprivate static let earthRadius = 6378000.0 // meter

  class func latitudeDegrees(fromMeter meter: Double) -> Double {
    return meter / earthRadius * (180 / Double.pi)
  }

  class func longitudeDegress(fromMeter meter: Double, latitude: Double) -> Double {
    return meter / earthRadius * (180 / Double.pi) / cos(latitude * Double.pi / 180)
  }
}

所以为了继续前进,我的代码如下所示:

let latitudeDelta = Converter.latitudeDegrees(fromMeter: speed)
let y = userLocation.latitude + latitudeDelta
let x = userLocation.longitude
let a = -self.mapView.camera.heading * Double.pi / 180
self.userLocation = CLLocationCoordinate2D(latitude: x*sin(a) + y*cos(a), longitude:x*cos(a) - y*sin(a))

我尝试了不同的方法,但似乎都没有奏效。有什么根本上的错误吗?难道我在计算中也需要考虑地球曲率?

【问题讨论】:

    标签: ios swift geolocation mapkit geo


    【解决方案1】:

    经过一番挣扎,我发现这个问题被称为“直接测地线问题”。 Here我找到了我需要的所有公式,但最后使用了一个很棒的C library

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2017-01-11
      • 1970-01-01
      相关资源
      最近更新 更多