From 53857f42f777e2b9753b8f00cce1a60ce3dcb8fd Mon Sep 17 00:00:00 2001
From: Riku <risaku@163.com>
Date: 星期三, 15 十月 2025 22:42:29 +0800
Subject: [PATCH] 2025.10.15 修改高德地图地理逆编码结果,让地理位置信息更加详细
---
src/test/kotlin/com/flightfeather/uav/Test.kt | 3 +
src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt | 2
src/main/kotlin/com/flightfeather/uav/biz/report/MissionRiskArea.kt | 15 +++++--
src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt | 50 +++++++++++++++----------
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt | 9 ++++
src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt | 2
6 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt
index 93403a2..8e21070 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataprocess/RoadSegment.kt
@@ -63,7 +63,7 @@
districtName = address.district
townCode = address.towncode
towmName = address.township
- street = address.street
+ street = address.address
})
}
// 缁撴灉鍏ュ簱
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt b/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt
index 5b928c4..710cc5f 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt
@@ -94,7 +94,7 @@
highRiskGrid!!.cell.longitude.toDouble()
to highRiskGrid!!.cell.latitude.toDouble()
))
- town = address.township + address.street
+ town = address.township + address.address
}
val polygon = listOf(
highRiskGrid!!.cell.point1Lon.toDouble() to highRiskGrid!!.cell.point1Lat.toDouble(),
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/report/MissionRiskArea.kt b/src/main/kotlin/com/flightfeather/uav/biz/report/MissionRiskArea.kt
index 570e3b8..4ac954c 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/report/MissionRiskArea.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/report/MissionRiskArea.kt
@@ -15,7 +15,12 @@
class ClueByArea {
var sceneInfo: SceneInfo? = null
+ // 鎵�灞炶闀�
+ var township:String? = null
+ // 鏍煎紡鍖栧湴鍧�
var address: String? = null
+ // 浜ゅ弶璺淇℃伅
+ var roadinter:String? = null
var clueByFactorList: MutableList<ClueByFactor>? = null
}
@@ -104,12 +109,14 @@
val dataList = pollutedClue.pollutedData?.dataList ?: emptyList()
if (dataList.isEmpty()) return@forEach
- // 鎸夋薄鏌撴函婧愬湴鍧�鍜屽洜瀛愬垎缁勭嚎绱�
- pollutedClue.pollutedArea?.address?.let { address ->
- var clueByArea = result.find { it.address == address }
+ // 鎸夋薄鏌撴函婧愬湴鍧�琛楅晣鍜屽洜瀛愬垎缁勭嚎绱�
+ pollutedClue.pollutedArea?.township?.let { township ->
+ var clueByArea = result.find { it.township == township }
if (clueByArea == null) {
clueByArea = ClueByArea().apply {
- this.address = address
+ this.township = township
+ this.address = pollutedClue.pollutedArea?.address
+ this.roadinter = pollutedClue.pollutedArea?.roadinter
this.clueByFactorList = mutableListOf()
}
result.add(clueByArea)
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
index 9993a86..8beb120 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
@@ -31,7 +31,12 @@
windLevelCondition?.let { sourceTrace(historyData, exceptionData, config, it) }
}
+ // 鎵�灞炶闀�
+ var township:String? = null
+ // 鏍煎紡鍖栧湴鍧�
var address: String? = null
+ // 浜ゅ弶璺淇℃伅
+ var roadinter:String? = null
// 姹℃煋鑼冨洿鎵囧舰鍖哄煙(缁忕含搴﹀杈瑰舰)
var polygon: List<Pair<Double, Double>>? = null
@@ -80,7 +85,9 @@
if (config.isSearchAddress) {
try {
val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(pair))
- this.address = address.district + address.township + address.street
+ this.township = address.province+address.district+address.township
+ this.address = address.address + address.streetNumber
+ this.roadinter = address.roadinter
// Thread.sleep(100)
} catch (e: Exception) {
e.printStackTrace()
diff --git a/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt b/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
index 0baf2e8..2740da2 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
@@ -1,13 +1,11 @@
package com.flightfeather.uav.common.net
import com.flightfeather.uav.common.exception.BizException
-import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.apache.http.util.EntityUtils
import java.net.URLEncoder
-import java.nio.charset.Charset
/**
* 楂樺痉鍦板浘Web鏈嶅姟API
@@ -29,7 +27,9 @@
val adcode: String,
val township: String,
val towncode: String,
- val street: String,
+ val address: String,
+ val streetNumber: String,
+ val roadinter: String,
)
data class AMapDirection(
@@ -48,7 +48,7 @@
/**
* 椹捐溅璺嚎瑙勫垝
*/
- fun directionDriving(origin: Pair<Double, Double>, destination: Pair<Double, Double>):AMapDirection {
+ fun directionDriving(origin: Pair<Double, Double>, destination: Pair<Double, Double>): AMapDirection {
val res = httpMethod.get(
"/v5/direction/driving", listOf(
"key" to KEY,
@@ -62,10 +62,10 @@
val count = obj["count"].asString.toIntOrNull()
if (count != null && count > 0) {
val path = obj["route"].asJsonObject["paths"].asJsonArray.get(0).asJsonObject
- val finalPaths = mutableListOf<Pair<Double,Double>>()
+ val finalPaths = mutableListOf<Pair<Double, Double>>()
path["steps"].asJsonArray.forEach {
finalPaths.addAll(
- it.asJsonObject["polyline"].asString.split(";").map { str->
+ it.asJsonObject["polyline"].asString.split(";").map { str ->
val strArr = str.split(",")
strArr[0].toDouble() to strArr[1].toDouble()
}
@@ -85,18 +85,22 @@
* @param location 鍧愭爣鐐�
* @return 鎵�鍦ㄨ閬�
*/
- fun reGeo(location:Pair<Double, Double>):AMapAddress {
- val res = httpMethod.get("/v3/geocode/regeo", listOf(
- "key" to KEY,
- "location" to "${location.first},${location.second}",
- "extensions" to "all"
- ))
+ fun reGeo(location: Pair<Double, Double>): AMapAddress {
+ val res = httpMethod.get(
+ "/v3/geocode/regeo", listOf(
+ "key" to KEY,
+ "location" to "${location.first},${location.second}",
+ "extensions" to "all"
+ )
+ )
val obj = handleRes(res)
try {
val regeocode = obj["regeocode"].asJsonObject
val a = regeocode["addressComponent"].asJsonObject
+ val streetNumber = a["streetNumber"].asJsonObject
val roads = regeocode["roads"].asJsonArray
val roadinters = regeocode["roadinters"].asJsonArray
+ val roadinter = if (roadinters.size() > 0) roadinters.get(0).asJsonObject else null
return AMapAddress(
a["country"].asString,
a["province"].asString,
@@ -106,7 +110,11 @@
a["adcode"].asString,
a["township"].asString,
a["towncode"].asString,
- a["streetNumber"].asJsonObject["street"].asString,
+ regeocode["formatted_address"].asString,
+ streetNumber["street"].asString + streetNumber["number"].asString
+ + streetNumber["direction"].asString + streetNumber["distance"].asDouble.toInt() + "绫�",
+ if(roadinter == null) "" else roadinter.get("first_name")?.asString +"鍜�" + roadinter.get("second_name")?.asString + "浜ゅ弶鍙�"
+ + roadinter.get("direction")?.asString + roadinter.get("distance")?.asDouble?.toInt() + "绫�",
)
} catch (e: Exception) {
throw BizException("楂樺痉API鍧愭爣杞崲閿欒锛�${e.message}", e.cause)
@@ -118,13 +126,15 @@
* @param locations 鍘熷鍧愭爣
* @param coordsys 鍘熷潗鏍囩郴锛屽彲閫夊�硷細gps;mapbar;baidu;autonavi(涓嶈繘琛岃浆鎹�)
*/
- fun coordinateConvert(locations: List<Pair<Double, Double>>, coordsys:String="gps"): List<Pair<Double, Double>> {
+ fun coordinateConvert(locations: List<Pair<Double, Double>>, coordsys: String = "gps"): List<Pair<Double, Double>> {
val locationsStr = URLEncoder.encode(locations.joinToString("|") { "${it.first},${it.second}" }, "UTF-8")
- val res = httpMethod.get("/v3/assistant/coordinate/convert", listOf(
- "key" to KEY,
- "locations" to locationsStr,
- "coordsys" to coordsys
- ))
+ val res = httpMethod.get(
+ "/v3/assistant/coordinate/convert", listOf(
+ "key" to KEY,
+ "locations" to locationsStr,
+ "coordsys" to coordsys
+ )
+ )
val obj = handleRes(res)
try {
return obj["locations"].asString.split(";").map {
@@ -136,7 +146,7 @@
}
}
- private fun handleRes(res: HttpMethod.MyResponse):JsonObject {
+ private fun handleRes(res: HttpMethod.MyResponse): JsonObject {
if (res.success) {
val str = EntityUtils.toString(res.m.entity)
val json = JsonParser.parseString(str)
diff --git a/src/test/kotlin/com/flightfeather/uav/Test.kt b/src/test/kotlin/com/flightfeather/uav/Test.kt
index db6bf8b..63b2781 100644
--- a/src/test/kotlin/com/flightfeather/uav/Test.kt
+++ b/src/test/kotlin/com/flightfeather/uav/Test.kt
@@ -202,6 +202,7 @@
@Test
fun reGeo() {
- AMapService.reGeo(MapUtil.wgs84ToGcj02(121.461753 to 31.252426))
+ val a = AMapService.reGeo(MapUtil.wgs84ToGcj02(121.45017 to 31.274426))
+ println(a)
}
}
\ No newline at end of file
--
Gitblit v1.9.3