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

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

View File

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