Integrate Amap SDK to replace CoreLocation and MapKit for all location features.
Unify GPS, reverse geocoding, and map display behind LocationProvider with privacy-gated bootstrap after login, aligned with Android. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
54
suixinkan/Features/Location/LocationProviding.swift
Normal file
54
suixinkan/Features/Location/LocationProviding.swift
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// LocationProviding.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
/// 位置采集结果。
|
||||
struct HomeLocationSnapshot: Sendable, Equatable {
|
||||
let latitude: Double
|
||||
let longitude: Double
|
||||
let address: String
|
||||
}
|
||||
|
||||
/// 定位服务协议,便于 ViewModel 注入与单元测试 mock。
|
||||
protocol LocationProviding: Sendable {
|
||||
/// 请求当前坐标与地址。
|
||||
func requestSnapshot() async throws -> HomeLocationSnapshot
|
||||
/// 请求当前坐标。
|
||||
func requestCoordinate() async throws -> CLLocationCoordinate2D
|
||||
/// 逆地理编码。
|
||||
func reverseGeocode(latitude: Double, longitude: Double) async -> String
|
||||
}
|
||||
|
||||
/// 定位错误。
|
||||
enum LocationProviderError: LocalizedError, Equatable {
|
||||
case privacyNotAccepted
|
||||
case permissionDenied
|
||||
case locationFailed
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .privacyNotAccepted:
|
||||
"请先阅读并同意隐私政策"
|
||||
case .permissionDenied:
|
||||
"需要定位权限才能使用此功能"
|
||||
case .locationFailed:
|
||||
"定位失败,请稍后重试"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 订单核销场景定位错误,保持原有提示文案。
|
||||
enum OrderLocationError: LocalizedError {
|
||||
case permissionDenied
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .permissionDenied:
|
||||
"缺少定位权限,功能无法进行"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user