I have a list of lat,long data in json format (AIRPORTS.jsin), I want to read it and convert it to polylines. After writing a function to do that, It does not show in the mapActivity
This is what I have done
fun getPolylines(fileName: String?):
MutableList<LatLng>? {
var polyline: LatLng
// array list of lines init
val polylines = mutableListOf<LatLng>()
val inputStream = fileName?.let {
application.assets.open(it).bufferedReader()
}
var Json_string = inputStream.use {
it?.readText() ?: null
}
// get json array
val jsonArray = JSONArray(Json_string)
for (i in 0 until jsonArray.length()) {
var jsonPolyline: JSONObject
try {
jsonPolyline = jsonArray.getJSONObject(i)
polyline = LatLng(
(jsonPolyline.getDouble("lat")),
(jsonPolyline.getDouble("lon"))
)
polylines.add(polyline)
} catch (e: JSONException) {
Log.d(ContentValues.TAG, "JSONException reading polylines: " + e.message)
} catch (e: Exception) {
Log.d(ContentValues.TAG, "Exception reading polylines: " + e.message)
}
}
return polylines
}
I then called it in onMapListener
//add polylines
var polylines: MutableList<LatLng>? = getPolylines("IPO_OMAGWA.json")
map.addPolyline(PolylineOptions()
.addAll(polylines!!)
.pattern(Arrays.asList(Dot(), Gap(10.0f)))
.geodesic(true)
.zIndex(5F)
)
but its not showing