swift-sgp4

一个 Swift 包,用于从双行轨道根数 (TLE) 计算卫星位置,封装了 sgp4lib 库(作者:Daniel Warner)

用法

import SGPKit

let title = "ISS (ZARYA)"
let firstLine = "1 25544U 98067A   13165.59097222  .00004759  00000-0  88814-4 0    47"
let secondLine = "2 25544  51.6478 121.2152 0011003  68.5125 263.9959 15.50783143834295"

// Instantiate a new TLE descriptor
let tle = TLE(title: title, firstLine: firstLine, secondLine: secondLine)

// Instantiate the interpreter
let interpreter = TLEInterpreter()

// Obtain the data
let data: SatelliteData = interpreter.satelliteData(from: tle, date: .now)

print(data.latitude)
print(data.longitude)
print(data.altitude)
print(data.speed)

安装

Swift 包管理器

如果你想在任何其他使用 SwiftPM 的项目中使用 SGPKit,请在 Package.swift 中添加该包作为依赖项

dependencies: [
  .package(
    url: "https://github.com/csanfilippo/swift-sgp4",
    from: "1.2.0"
  ),
]