diff --git a/app/src/main/assets/Log.txt b/app/src/main/assets/Log.txt new file mode 100644 index 0000000..3ac0c06 --- /dev/null +++ b/app/src/main/assets/Log.txt @@ -0,0 +1,36 @@ +[2024-05-08 10:55:03, 116.26520111153543, 39.914095876958136] +[2024-05-08 10:55:23, 116.26520041477461, 39.91408176744235] +[2024-05-08 10:55:25, 116.26521381618639, 39.914085321105404] +[2024-05-08 10:55:27, 116.26521469085102, 39.91408589424658] +[2024-05-08 10:55:29, 116.26521935112915, 39.91408948155932] +[2024-05-08 10:55:31, 116.26521674438393, 39.91409277640618] +[2024-05-08 10:55:33, 116.26521502100081, 39.91409680623537] +[2024-05-08 10:55:35, 116.26521436528681, 39.91409743870871] +[2024-05-08 10:55:37, 116.26521581852678, 39.914096215019896] +[2024-05-08 10:55:39, 116.2652157997227, 39.91409655274152] +[2024-05-08 10:55:41, 116.26521525332545, 39.914089595841055] +[2024-05-08 10:55:43, 116.26521547696976, 39.91408284152685] +[2024-05-08 10:55:45, 116.26521702403849, 39.91408110674177] +[2024-05-08 10:55:47, 116.26521601937341, 39.91408169851284] +[2024-05-08 10:55:49, 116.26521878070947, 39.91408256547792] +[2024-05-08 10:55:51, 116.26521493263463, 39.91408460388276] +[2024-05-08 10:55:53, 116.2652065596182, 39.914083330147676] +[2024-05-08 10:55:55, 116.26520718302675, 39.914091775582044] +[2024-05-08 10:55:57, 116.2652105172751, 39.91409413348714] +[2024-05-08 10:56:00, 116.26521310207109, 39.914091631929594] +[2024-05-08 10:56:02, 116.26521468002292, 39.91409136586091] +[2024-05-08 10:56:04, 116.26521630161699, 39.914091848890436] +[2024-05-08 10:56:06, 116.26521525210667, 39.91409125637526] +[2024-05-08 10:56:08, 116.2652154868529, 39.914091114790416] +[2024-05-08 10:56:10, 116.26521685507166, 39.91409297065138] +[2024-05-08 10:56:12, 116.26521859251761, 39.91410895855137] +[2024-05-08 10:56:14, 116.26521574096462, 39.91411681129428] +[2024-05-08 10:56:16, 116.26521586107947, 39.91411806262725] +[2024-05-08 10:56:18, 116.26521655541322, 39.91411783085555] +[2024-05-08 10:56:20, 116.26521718046945, 39.91411551340897] +[2024-05-08 10:56:22, 116.26521771440684, 39.914113376894825] +[2024-05-08 10:56:24, 116.26521390349613, 39.91410998932012] +[2024-05-08 10:56:26, 116.26520710330637, 39.91411181374916] +[2024-05-08 10:56:28, 116.26520472814147, 39.91410742271341] +[2024-05-08 10:56:30, 116.26520492008224, 39.914108851730944] +[2024-05-08 10:56:32, 116.26520370261551, 39.91410741613028] \ No newline at end of file diff --git a/app/src/main/assets/Log.txt b/app/src/main/assets/Log.txt new file mode 100644 index 0000000..3ac0c06 --- /dev/null +++ b/app/src/main/assets/Log.txt @@ -0,0 +1,36 @@ +[2024-05-08 10:55:03, 116.26520111153543, 39.914095876958136] +[2024-05-08 10:55:23, 116.26520041477461, 39.91408176744235] +[2024-05-08 10:55:25, 116.26521381618639, 39.914085321105404] +[2024-05-08 10:55:27, 116.26521469085102, 39.91408589424658] +[2024-05-08 10:55:29, 116.26521935112915, 39.91408948155932] +[2024-05-08 10:55:31, 116.26521674438393, 39.91409277640618] +[2024-05-08 10:55:33, 116.26521502100081, 39.91409680623537] +[2024-05-08 10:55:35, 116.26521436528681, 39.91409743870871] +[2024-05-08 10:55:37, 116.26521581852678, 39.914096215019896] +[2024-05-08 10:55:39, 116.2652157997227, 39.91409655274152] +[2024-05-08 10:55:41, 116.26521525332545, 39.914089595841055] +[2024-05-08 10:55:43, 116.26521547696976, 39.91408284152685] +[2024-05-08 10:55:45, 116.26521702403849, 39.91408110674177] +[2024-05-08 10:55:47, 116.26521601937341, 39.91408169851284] +[2024-05-08 10:55:49, 116.26521878070947, 39.91408256547792] +[2024-05-08 10:55:51, 116.26521493263463, 39.91408460388276] +[2024-05-08 10:55:53, 116.2652065596182, 39.914083330147676] +[2024-05-08 10:55:55, 116.26520718302675, 39.914091775582044] +[2024-05-08 10:55:57, 116.2652105172751, 39.91409413348714] +[2024-05-08 10:56:00, 116.26521310207109, 39.914091631929594] +[2024-05-08 10:56:02, 116.26521468002292, 39.91409136586091] +[2024-05-08 10:56:04, 116.26521630161699, 39.914091848890436] +[2024-05-08 10:56:06, 116.26521525210667, 39.91409125637526] +[2024-05-08 10:56:08, 116.2652154868529, 39.914091114790416] +[2024-05-08 10:56:10, 116.26521685507166, 39.91409297065138] +[2024-05-08 10:56:12, 116.26521859251761, 39.91410895855137] +[2024-05-08 10:56:14, 116.26521574096462, 39.91411681129428] +[2024-05-08 10:56:16, 116.26521586107947, 39.91411806262725] +[2024-05-08 10:56:18, 116.26521655541322, 39.91411783085555] +[2024-05-08 10:56:20, 116.26521718046945, 39.91411551340897] +[2024-05-08 10:56:22, 116.26521771440684, 39.914113376894825] +[2024-05-08 10:56:24, 116.26521390349613, 39.91410998932012] +[2024-05-08 10:56:26, 116.26520710330637, 39.91411181374916] +[2024-05-08 10:56:28, 116.26520472814147, 39.91410742271341] +[2024-05-08 10:56:30, 116.26520492008224, 39.914108851730944] +[2024-05-08 10:56:32, 116.26520370261551, 39.91410741613028] \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index eadd334..55012a7 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -92,6 +92,7 @@ import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.readAssetsFile import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.extensions.timestampToCompleteDate import com.pengxh.kt.lite.extensions.timestampToTime @@ -110,6 +111,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File +import java.math.RoundingMode +import java.text.DecimalFormat import java.util.Calendar import java.util.Date import java.util.Timer @@ -127,14 +130,13 @@ private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private val detailDialog by lazy { MarkerDetailDialog(this) } private val locationHub by lazy { LocationHub(this) } + private val decimalFormat by lazy { DecimalFormat("0.00") } private val sensorMessageCode = 2024022301 private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var markers = ArrayList() private var clusterOverlay: ClusterOverlay? = null - private var latitude: Double = 0.0 - private var longitude: Double = 0.0 private var isFreeTask = false private var freeTaskTitle = "" private var ids = HashSet() @@ -174,6 +176,9 @@ slowSoundResourceId = soundPool.load(this, R.raw.ring4, 1) fastSoundResourceId = soundPool.load(this, R.raw.ring2, 1) + //保留小数2位 + decimalFormat.roundingMode = RoundingMode.HALF_UP + "登录成功".show(this) //地图初始化 @@ -649,8 +654,6 @@ aMap.myLocationStyle = locationStyle//设置定位蓝点的Style aMap.isMyLocationEnabled = true//设置是否显示定位小蓝点 aMap.setOnMyLocationChangeListener { - longitude = it.longitude - latitude = it.latitude //经纬度逆编码 locationHub.antiCodingLocation(it) { address -> binding.currentLocationView.text = address @@ -1554,14 +1557,30 @@ override fun show() { super.show() + //TODO 将测试点文本数据序列化 + val assetsFileContent = readAssetsFile("Log.txt") + val result = ArrayList() + for (line in assetsFileContent.split("]")) { + if (line.isBlank()) { + continue + } + val split = line.replace("[", "").split(",") + val double = DoubleArray(2) + double[0] = split[1].replace(" ", "").toDouble() + double[1] = split[2].replace(" ", "").toDouble() + + result.add(double) + } + locationManager = LocationHub(context) //点位渲染,每次定位都计算当前位置与符合条件的点距离 locationManager.getCurrentLocation(false, object : OnGetLocationListener { override fun onAMapLocationGet(location: AMapLocation?) { + val random = result.random() location?.apply { val time = System.currentTimeMillis().timestampToCompleteDate() "[$time, ${longitude}, ${latitude}]".writeToFile(createLogFile()) - renderDataPoint(this) + renderDataPoint(this, random) } } }) @@ -1570,14 +1589,16 @@ /** * 计算并渲染数据点。点太多采用协程计算,不然会有点卡顿 * @param location 定位点(天宝RTK获取) + * @param testPoint 模拟点 * */ - private fun renderDataPoint(location: AMapLocation) { + private fun renderDataPoint(location: AMapLocation, testPoint: DoubleArray) { lifecycleScope.launch(Dispatchers.IO) { val dataPoints = ArrayList() DataBaseManager.get.loadMarkers().forEach { - //单位:米。计算出探测仪(定位点)与标识器距离 + //单位:米。计算出标识器与探测仪(定位点)的距离 val distance = AMapUtils.calculateLineDistance( - LatLng(latitude, longitude), LatLng(it.lat.toDouble(), it.lng.toDouble()) + LatLng(it.lat.toDouble(), it.lng.toDouble()), + LatLng(location.latitude, location.longitude) ) if (distance <= LocaleConstant.MAX_DISTANCE) { @@ -1586,19 +1607,38 @@ LatLng(it.lat.toDouble(), it.lng.toDouble()) ) - val formatDistance = String.format("%.2f", distance) + val formatDistance = decimalFormat.format(distance) dataPoints.add(RadarScanView.DataPoint(angle, formatDistance.toFloat())) } + +// if (it.markerId == "0008865561" || it.markerId == "0008877280") { +// val distance = AMapUtils.calculateLineDistance( +// LatLng(it.lat.toDouble(), it.lng.toDouble()), +// LatLng(testPoint[1], testPoint[0]) +// ) +// +// if (distance <= LocaleConstant.MAX_DISTANCE) { +// //计算出探测仪(定位点)与标识器的方位角 +// val angle = location.calculateAngle( +// LatLng(it.lat.toDouble(), it.lng.toDouble()) +// ) +// +// val formatDistance = decimalFormat.format(distance) +// Log.d(kTag, "${testPoint[1]}, ${testPoint[0]}, $formatDistance, $angle") +// +// dataPoints.add(RadarScanView.DataPoint(angle, formatDistance.toFloat())) +// } +// } } withContext(Dispatchers.Main) { binding.radarScanView.renderPointData(dataPoints, object : RadarScanView.OnGetNearestPointCallback { override fun getNearestPoint(point: RadarScanView.DataPoint?) { if (point == null) { - binding.distanceValueView.text = "大于550cm" + binding.distanceValueView.text = "大于5.5m" binding.distancePgBar.progress = 100 } else { - binding.distanceValueView.text = "${point.distance * 100}cm" + binding.distanceValueView.text = "${point.distance}m" val progress = if (point.distance > LocaleConstant.MAX_DISTANCE) { 100 diff --git a/app/src/main/assets/Log.txt b/app/src/main/assets/Log.txt new file mode 100644 index 0000000..3ac0c06 --- /dev/null +++ b/app/src/main/assets/Log.txt @@ -0,0 +1,36 @@ +[2024-05-08 10:55:03, 116.26520111153543, 39.914095876958136] +[2024-05-08 10:55:23, 116.26520041477461, 39.91408176744235] +[2024-05-08 10:55:25, 116.26521381618639, 39.914085321105404] +[2024-05-08 10:55:27, 116.26521469085102, 39.91408589424658] +[2024-05-08 10:55:29, 116.26521935112915, 39.91408948155932] +[2024-05-08 10:55:31, 116.26521674438393, 39.91409277640618] +[2024-05-08 10:55:33, 116.26521502100081, 39.91409680623537] +[2024-05-08 10:55:35, 116.26521436528681, 39.91409743870871] +[2024-05-08 10:55:37, 116.26521581852678, 39.914096215019896] +[2024-05-08 10:55:39, 116.2652157997227, 39.91409655274152] +[2024-05-08 10:55:41, 116.26521525332545, 39.914089595841055] +[2024-05-08 10:55:43, 116.26521547696976, 39.91408284152685] +[2024-05-08 10:55:45, 116.26521702403849, 39.91408110674177] +[2024-05-08 10:55:47, 116.26521601937341, 39.91408169851284] +[2024-05-08 10:55:49, 116.26521878070947, 39.91408256547792] +[2024-05-08 10:55:51, 116.26521493263463, 39.91408460388276] +[2024-05-08 10:55:53, 116.2652065596182, 39.914083330147676] +[2024-05-08 10:55:55, 116.26520718302675, 39.914091775582044] +[2024-05-08 10:55:57, 116.2652105172751, 39.91409413348714] +[2024-05-08 10:56:00, 116.26521310207109, 39.914091631929594] +[2024-05-08 10:56:02, 116.26521468002292, 39.91409136586091] +[2024-05-08 10:56:04, 116.26521630161699, 39.914091848890436] +[2024-05-08 10:56:06, 116.26521525210667, 39.91409125637526] +[2024-05-08 10:56:08, 116.2652154868529, 39.914091114790416] +[2024-05-08 10:56:10, 116.26521685507166, 39.91409297065138] +[2024-05-08 10:56:12, 116.26521859251761, 39.91410895855137] +[2024-05-08 10:56:14, 116.26521574096462, 39.91411681129428] +[2024-05-08 10:56:16, 116.26521586107947, 39.91411806262725] +[2024-05-08 10:56:18, 116.26521655541322, 39.91411783085555] +[2024-05-08 10:56:20, 116.26521718046945, 39.91411551340897] +[2024-05-08 10:56:22, 116.26521771440684, 39.914113376894825] +[2024-05-08 10:56:24, 116.26521390349613, 39.91410998932012] +[2024-05-08 10:56:26, 116.26520710330637, 39.91411181374916] +[2024-05-08 10:56:28, 116.26520472814147, 39.91410742271341] +[2024-05-08 10:56:30, 116.26520492008224, 39.914108851730944] +[2024-05-08 10:56:32, 116.26520370261551, 39.91410741613028] \ No newline at end of file diff --git a/app/src/main/java/com/casic/detector/view/MainActivity.kt b/app/src/main/java/com/casic/detector/view/MainActivity.kt index eadd334..55012a7 100644 --- a/app/src/main/java/com/casic/detector/view/MainActivity.kt +++ b/app/src/main/java/com/casic/detector/view/MainActivity.kt @@ -92,6 +92,7 @@ import com.pengxh.kt.lite.extensions.initDialogLayoutParams import com.pengxh.kt.lite.extensions.isNetworkConnected import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.readAssetsFile import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.extensions.timestampToCompleteDate import com.pengxh.kt.lite.extensions.timestampToTime @@ -110,6 +111,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File +import java.math.RoundingMode +import java.text.DecimalFormat import java.util.Calendar import java.util.Date import java.util.Timer @@ -127,14 +130,13 @@ private val searchNewDialog by lazy { SearchMarkerNewDialog(this) } private val detailDialog by lazy { MarkerDetailDialog(this) } private val locationHub by lazy { LocationHub(this) } + private val decimalFormat by lazy { DecimalFormat("0.00") } private val sensorMessageCode = 2024022301 private val rotationMatrix = FloatArray(9)//旋转矩阵缓存 private val valueArray = FloatArray(3)//方位角数值 private var clickTime: Long = 0 private var markers = ArrayList() private var clusterOverlay: ClusterOverlay? = null - private var latitude: Double = 0.0 - private var longitude: Double = 0.0 private var isFreeTask = false private var freeTaskTitle = "" private var ids = HashSet() @@ -174,6 +176,9 @@ slowSoundResourceId = soundPool.load(this, R.raw.ring4, 1) fastSoundResourceId = soundPool.load(this, R.raw.ring2, 1) + //保留小数2位 + decimalFormat.roundingMode = RoundingMode.HALF_UP + "登录成功".show(this) //地图初始化 @@ -649,8 +654,6 @@ aMap.myLocationStyle = locationStyle//设置定位蓝点的Style aMap.isMyLocationEnabled = true//设置是否显示定位小蓝点 aMap.setOnMyLocationChangeListener { - longitude = it.longitude - latitude = it.latitude //经纬度逆编码 locationHub.antiCodingLocation(it) { address -> binding.currentLocationView.text = address @@ -1554,14 +1557,30 @@ override fun show() { super.show() + //TODO 将测试点文本数据序列化 + val assetsFileContent = readAssetsFile("Log.txt") + val result = ArrayList() + for (line in assetsFileContent.split("]")) { + if (line.isBlank()) { + continue + } + val split = line.replace("[", "").split(",") + val double = DoubleArray(2) + double[0] = split[1].replace(" ", "").toDouble() + double[1] = split[2].replace(" ", "").toDouble() + + result.add(double) + } + locationManager = LocationHub(context) //点位渲染,每次定位都计算当前位置与符合条件的点距离 locationManager.getCurrentLocation(false, object : OnGetLocationListener { override fun onAMapLocationGet(location: AMapLocation?) { + val random = result.random() location?.apply { val time = System.currentTimeMillis().timestampToCompleteDate() "[$time, ${longitude}, ${latitude}]".writeToFile(createLogFile()) - renderDataPoint(this) + renderDataPoint(this, random) } } }) @@ -1570,14 +1589,16 @@ /** * 计算并渲染数据点。点太多采用协程计算,不然会有点卡顿 * @param location 定位点(天宝RTK获取) + * @param testPoint 模拟点 * */ - private fun renderDataPoint(location: AMapLocation) { + private fun renderDataPoint(location: AMapLocation, testPoint: DoubleArray) { lifecycleScope.launch(Dispatchers.IO) { val dataPoints = ArrayList() DataBaseManager.get.loadMarkers().forEach { - //单位:米。计算出探测仪(定位点)与标识器距离 + //单位:米。计算出标识器与探测仪(定位点)的距离 val distance = AMapUtils.calculateLineDistance( - LatLng(latitude, longitude), LatLng(it.lat.toDouble(), it.lng.toDouble()) + LatLng(it.lat.toDouble(), it.lng.toDouble()), + LatLng(location.latitude, location.longitude) ) if (distance <= LocaleConstant.MAX_DISTANCE) { @@ -1586,19 +1607,38 @@ LatLng(it.lat.toDouble(), it.lng.toDouble()) ) - val formatDistance = String.format("%.2f", distance) + val formatDistance = decimalFormat.format(distance) dataPoints.add(RadarScanView.DataPoint(angle, formatDistance.toFloat())) } + +// if (it.markerId == "0008865561" || it.markerId == "0008877280") { +// val distance = AMapUtils.calculateLineDistance( +// LatLng(it.lat.toDouble(), it.lng.toDouble()), +// LatLng(testPoint[1], testPoint[0]) +// ) +// +// if (distance <= LocaleConstant.MAX_DISTANCE) { +// //计算出探测仪(定位点)与标识器的方位角 +// val angle = location.calculateAngle( +// LatLng(it.lat.toDouble(), it.lng.toDouble()) +// ) +// +// val formatDistance = decimalFormat.format(distance) +// Log.d(kTag, "${testPoint[1]}, ${testPoint[0]}, $formatDistance, $angle") +// +// dataPoints.add(RadarScanView.DataPoint(angle, formatDistance.toFloat())) +// } +// } } withContext(Dispatchers.Main) { binding.radarScanView.renderPointData(dataPoints, object : RadarScanView.OnGetNearestPointCallback { override fun getNearestPoint(point: RadarScanView.DataPoint?) { if (point == null) { - binding.distanceValueView.text = "大于550cm" + binding.distanceValueView.text = "大于5.5m" binding.distancePgBar.progress = 100 } else { - binding.distanceValueView.text = "${point.distance * 100}cm" + binding.distanceValueView.text = "${point.distance}m" val progress = if (point.distance > LocaleConstant.MAX_DISTANCE) { 100 diff --git a/app/src/main/res/layout/dialog_search_marker_new.xml b/app/src/main/res/layout/dialog_search_marker_new.xml index e9a97a0..f359b78 100644 --- a/app/src/main/res/layout/dialog_search_marker_new.xml +++ b/app/src/main/res/layout/dialog_search_marker_new.xml @@ -119,7 +119,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="@font/fzdhjt" - android:text="距离(cm):" + android:text="距离(m):" android:textColor="@color/white" />