【发布时间】:2021-10-13 21:01:13
【问题描述】:
我想将共享首选项中的值转换为 LatLng 对的可变列表以绘制折线。我不知道如何转换它。请帮助。在这里,我将共享首选项polyl 中的值设为 [lat/lng:(10.184133,76.4005395),lat/lng(10.1840907,76.4004505)] 等。如何将其转换为 LatLng 对的可变列表,以便绘制折线。
val sharedPr= activity?.getPreferences(Context.MODE_PRIVATE)
val polyl= sharedPr?.getString("polylinep",null)
Toast.makeText(requireContext() ,"$polyl", Toast.LENGTH_SHORT).show()
try {
val polyline10= polyl as MutableList<LatLng>
Toast.makeText(requireContext() ,"ub$polyline10", Toast.LENGTH_SHORT).show()
map.addPolyline(
PolylineOptions().apply {
width(10f)
color(Color.BLUE)
jointType(JointType.ROUND)
startCap(ButtCap())
endCap(ButtCap())
addAll(polyline10)
}
)
} catch (e:java.lang.ClassCastException){
}
【问题讨论】:
标签: android google-maps kotlin google-polyline polylineoptions