优化首页位置上报体验

This commit is contained in:
2026-07-10 11:44:56 +08:00
parent c03a625409
commit df547a16dc
8 changed files with 47 additions and 11 deletions

View File

@ -20,12 +20,12 @@ final class LocationProvider: NSObject, LocationProviding {
permissionManager.desiredAccuracy = kCLLocationAccuracyBest
}
func requestSnapshot() async throws -> HomeLocationSnapshot {
func requestSnapshot(desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest) async throws -> HomeLocationSnapshot {
try AMapBootstrap.requireConfigured()
try await ensureLocationPermission()
let manager = makeLocationManager(
desiredAccuracy: kCLLocationAccuracyBest,
desiredAccuracy: desiredAccuracy,
locatingWithReGeocode: true
)
return try await withCheckedThrowingContinuation { continuation in

View File

@ -15,8 +15,8 @@ struct HomeLocationSnapshot: Sendable, Equatable {
/// 便 ViewModel mock
protocol LocationProviding: Sendable {
///
func requestSnapshot() async throws -> HomeLocationSnapshot
///
func requestSnapshot(desiredAccuracy: CLLocationAccuracy) async throws -> HomeLocationSnapshot
///
func requestCoordinate(desiredAccuracy: CLLocationAccuracy) async throws -> CLLocationCoordinate2D
///
@ -24,6 +24,11 @@ protocol LocationProviding: Sendable {
}
extension LocationProviding {
/// 使
func requestSnapshot() async throws -> HomeLocationSnapshot {
try await requestSnapshot(desiredAccuracy: kCLLocationAccuracyBest)
}
/// 使
func requestCoordinate() async throws -> CLLocationCoordinate2D {
try await requestCoordinate(desiredAccuracy: kCLLocationAccuracyBest)

View File

@ -3,6 +3,7 @@
// suixinkan
//
import CoreLocation
import Foundation
///
@ -16,6 +17,7 @@ struct LocationReportSuccessResult: Equatable {
final class LocationReportService {
static let operationIntervalMillis: Int64 = 30_000
static let manualReportDesiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyHundredMeters
private(set) var lastOnlineStatusSwitchTime: Int64 = 0
private(set) var lastLocationReportTime: Int64 = 0
@ -87,7 +89,8 @@ final class LocationReportService {
longitude: nil,
address: nil,
type: 1,
showSuccessToast: true
showSuccessToast: true,
desiredAccuracy: Self.manualReportDesiredAccuracy
)
}
@ -98,7 +101,8 @@ final class LocationReportService {
longitude: Double?,
address: String?,
type: Int,
showSuccessToast: Bool = true
showSuccessToast: Bool = true,
desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest
) async throws -> LocationReportSuccessResult {
if type != 3 {
let now = currentTimestampMillis()
@ -136,7 +140,7 @@ final class LocationReportService {
address: resolvedAddress
)
} else {
snapshot = try await locationProvider.requestSnapshot()
snapshot = try await locationProvider.requestSnapshot(desiredAccuracy: desiredAccuracy)
}
let locationText = snapshot.address.isEmpty