jsdw_ios/QuickLocation/Tool/GPSSignalHelper.swift

33 lines
807 B
Swift
Raw Permalink 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
}
}