添加位置信息浮动层,显示定位状态

This commit is contained in:
2026-02-28 18:25:45 +08:00
parent e8be0ef93f
commit 04e8290a8a
1277 changed files with 45436 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import android.content.Context
import android.location.Geocoder
import android.location.Location
import android.os.Looper
import android.util.Log
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
@@ -67,13 +68,16 @@ class LocationHelper(private val context: Context) {
* 获取位置信息(地址或经纬度)
*/
suspend fun getLocationInfo(useNetwork: Boolean = true): String {
Log.d("LocationHelper", "Getting location, useNetwork=$useNetwork")
if (!useNetwork) {
val location = getCurrentLocation() ?: return ""
return "${"%.4f".format(location.latitude)}, ${"%.4f".format(location.longitude)}"
val location = getCurrentLocation()
Log.d("LocationHelper", "GPS location: $location")
return location?.let { "${"%.4f".format(it.latitude)}, ${"%.4f".format(it.longitude)}" } ?: ""
}
val location = getCurrentLocation() ?: return ""
return getAddressFromLocation(location.latitude, location.longitude)
val location = getCurrentLocation()
Log.d("LocationHelper", "Network location: $location")
return location?.let { getAddressFromLocation(it.latitude, it.longitude) } ?: ""
}
}