From 723780b7cc1fdddadfe576aa82eec79ea3cc0454 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 12 Aug 2025 11:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../location_service/LocationService.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt index fcdc8ce17..59bea1b2f 100644 --- a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt +++ b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt @@ -16,6 +16,7 @@ import io.flutter.plugin.common.MethodChannel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.json.JSONObject object LocationService { @@ -115,6 +116,15 @@ object LocationService { } initialized = true + //首次请求一次定位 + requestLocation(object : LocationCallback { + override fun onLocationSuccess(latitude: Double, longitude: Double) { + } + + override fun onLocationError(errorCode: Int, errorMessage: String) { + } + }) + Log.d(TAG, "定位服务初始化完成 - 优化高精度模式") } catch (e: Exception) { Log.e(TAG, "高德定位初始化失败: ${e.message}", e) @@ -173,14 +183,6 @@ object LocationService { } Log.d(TAG, "定位结果: 来源=${location.provider}, 精度=${location.accuracy}米, 坐标=(${location.latitude}, ${location.longitude})") - - // 检查定位来源,只接受GPS定位 - if (location.provider != "gps") { - Log.w(TAG, "拒绝非GPS定位,当前来源: ${location.provider}") - // 继续等待GPS定位,不回调 - return - } - if (location.errorCode == AMapLocation.LOCATION_SUCCESS) { val accuracy = location.accuracy Log.d(TAG, "GPS定位成功: 精度=${accuracy}米")