国内经纬度转换后反地理显示

This commit is contained in:
yezhiqiu
2026-03-11 11:38:39 +08:00
parent f5001f3349
commit 1bc92e860f
2 changed files with 10 additions and 4 deletions

View File

@@ -98,6 +98,9 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
//是否可用直播
private var isCanLive = false
//是否需要gps坐标转火星坐标
private var needGpsToGCJ02 = true
companion object {
@JvmStatic
fun newInstance(context: Context) = MapV3Fragment().apply {
@@ -507,6 +510,7 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
if (mPetList.size == 0) {
return
}
needGpsToGCJ02 = true
mCountDownTimerViewModel.isStartCountDown = false
mCurrentShowPetPos = position
@@ -564,8 +568,11 @@ class MapV3Fragment : BaseFragment<FragmentMapV3Binding>(FragmentMapV3Binding::i
mHomeMapCommon.switchShowLocation(ConstantInt.UserLocationType)
} else {
//判断是否国内经纬度,需要坐标转换
val isOutOfChina = LonAndLatUtil.isLocationOutOfChina(latitude, longitude)
MMKVUtil.putBoolean(MMKVKey.isGpsToGCJ02, !isOutOfChina)
if (needGpsToGCJ02) {
needGpsToGCJ02 = false
val isOutOfChina = LonAndLatUtil.isLocationOutOfChina(latitude, longitude)
MMKVUtil.putBoolean(MMKVKey.isGpsToGCJ02, !isOutOfChina)
}
mHomeMapCommon.refreshPetCurrentLocation(latitude, longitude, isMoveCamera)
isMoveCamera = false
}

View File

@@ -74,8 +74,7 @@ class GeoCoderViewModel : ViewModel() {
baiduMapReverseGeocoder(latitude, longitude)
} else {
if (MMKVUtil.getBoolean(MMKVKey.isGpsToGCJ02)) {
val convertLatLon = LonAndLatUtil.convertFromWGS84ToGCJ02(latitude, longitude)
mapBoxReverseGeocoder(convertLatLon[0], convertLatLon[1])
baiduMapReverseGeocoder(latitude, longitude)
} else {
mapBoxReverseGeocoder(latitude, longitude)
}