diff --git a/core/function-impl/mogo-core-function-map/src/main/assets/planningDataTest.txt b/core/function-impl/mogo-core-function-map/src/main/assets/planningDataTest.txt new file mode 100644 index 0000000000..a40201868c --- /dev/null +++ b/core/function-impl/mogo-core-function-map/src/main/assets/planningDataTest.txt @@ -0,0 +1 @@ +全局路径规划的GSON格式的轨迹点数据放这里,然后使用PlanningDataUtils工具类解析一下 \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/utils/PlanningDataUtils.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/utils/PlanningDataUtils.kt new file mode 100644 index 0000000000..2c66808897 --- /dev/null +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/utils/PlanningDataUtils.kt @@ -0,0 +1,50 @@ +package com.mogo.eagle.core.function.utils + +import android.content.Context +import mogo.telematics.pad.MessagePad +import org.json.JSONArray +import org.json.JSONException +import java.io.IOException +import java.io.InputStream + +object PlanningDataUtils { + + @JvmStatic + fun test(context: Context?): List { + if (context == null) return emptyList() + val list: MutableList = ArrayList() + val jsonStr = getAssetsString(context, "planningDataTest.txt") + try { + val jsonElements = JSONArray(jsonStr) + for (i in 0 until jsonElements.length()) { + val s = jsonElements.getJSONObject(i) + val builder = MessagePad.Location.newBuilder() + builder.latitude = s.getDouble("latitude") + builder.longitude = s.getDouble("longitude") + list.add(builder.build()) + } + } catch (e: JSONException) { + e.printStackTrace() + } + return list + } + + private fun getAssetsString(context: Context, fileName: String): String { + var buffer: ByteArray? = null + var istream: InputStream? = null + try { + istream = context.resources.assets.open(fileName) + buffer = ByteArray(istream.available()) + istream.read(buffer) + } catch (e: IOException) { + e.printStackTrace() + } finally { + try { + istream?.close() + } catch (e: IOException) { + e.printStackTrace() + } + } + return String(buffer!!) + } +} \ No newline at end of file