jsdw_ios/QuickLocation/Tool/GPSSignalHelper.swift

33 lines
807 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// GPSSignalHelper.swift
// QuickLocation
//
// Created by 八条 on 2026/6/18.
//
import CoreLocation
/// GPS 信号强度(4 格)
enum GPSSignalStrength: Int {
case none = 0
case weak = 1
case fair = 2
case good = 3
case excellent = 4
var barCount: Int { rawValue }
}
/// 根据 CLLocation 的 horizontalAccuracy 估算 GPS 信号强度
func gpsSignalStrength(from location: CLLocation?) -> GPSSignalStrength {
guard let loc = location else { return .none }
let acc = loc.horizontalAccuracy
guard acc > 0 else { return .none }
switch acc {
case ..<10: return .excellent // GPS 锁定强
case ..<30: return .good // GPS 良好
case ..<100: return .fair // 一般
default: return .weak // 基站/WiFi
}
}