Files
suixinkan_uikit/suixinkan/Features/Location/LocationGeocoder.swift
汉秋 5eef31b8da 完善景区排队设置页与全局按钮配置迁移。
重构排队设置与变更日志交互,补充 Overlay 与资源,并将多页面主操作按钮统一到 UIButton Configuration,同步更新相关单元测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 16:51:23 +08:00

66 lines
1.9 KiB
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.

//
// LocationGeocoder.swift
// suixinkan
//
import Foundation
/// Android `GeocodeSearch`
@MainActor
final class LocationGeocoder: NSObject, AMapSearchDelegate {
nonisolated static let shared = LocationGeocoder()
private var searchAPI: AMapSearchAPI?
private var continuation: CheckedContinuation<String, Never>?
nonisolated private override init() {
super.init()
}
///
func reverseGeocode(latitude: Double, longitude: Double) async -> String {
do {
try AMapBootstrap.requireConfigured()
} catch {
return ""
}
return await withCheckedContinuation { continuation in
self.continuation?.resume(returning: "")
self.continuation = continuation
guard let api = makeSearchAPI() else {
continuation.resume(returning: "")
return
}
let request = AMapReGeocodeSearchRequest()
request.location = AMapGeoPoint.location(withLatitude: CGFloat(latitude), longitude: CGFloat(longitude))
request.requireExtension = true
request.radius = 200
api.aMapReGoecodeSearch(request)
}
}
func onReGeocodeSearchDone(_ request: AMapReGeocodeSearchRequest!, response: AMapReGeocodeSearchResponse!) {
let address = response?.regeocode?.formattedAddress ?? ""
continuation?.resume(returning: address)
continuation = nil
}
func aMapSearchRequest(_ request: Any!, didFailWithError error: Error!) {
continuation?.resume(returning: "")
continuation = nil
}
private func makeSearchAPI() -> AMapSearchAPI? {
if let searchAPI {
return searchAPI
}
guard let api = AMapSearchAPI() else { return nil }
api.delegate = self
searchAPI = api
return api
}
}