I have created an application that, given two input points, calls a function that draws a path, on a map, between the two points. I would now like to be able to implement the ability to click on the path and save it locally, in a list, so that I can retrieve it when necessary.
I'm a beginner with programming in kotlin and android, could you advise me how to do it?
I share below the function that I use to create the path in case it is useful.
fun routePath(p1Latit: Double, p1Laong: Double, p2Latit: Double, p2Laong: Double){
val roadManager: RoadManager = OSRMRoadManager(context, "lolloMaps")
OSRMRoadManager.MEAN_BY_FOOT
val waypoints = arrayListOf<GeoPoint>()
val startPoint: GeoPoint = GeoPoint(p1Latit, p1Laong)
waypoints.add(startPoint)
val endPoint: GeoPoint = GeoPoint(p2Latit, p2Laong)
waypoints.add(endPoint)
mapView.overlays.forEach{
if (it is Polyline && it.id == "Path"){
mapView.overlays.remove(it)
}
}
road = roadManager.getRoad(waypoints)
if (road.mStatus != Road.STATUS_OK){
Toast.makeText(context, "Error - status = " + road.mStatus, Toast.LENGTH_SHORT).show()
}
val roadOverlay: Polyline = RoadManager.buildRoadOverlay(road)
roadOverlay.id = "Path"
mapView.overlays.add(roadOverlay)
mapView.invalidate()
val nodeIcon: Drawable? = ResourcesCompat.getDrawable(mapView.resources, R.drawable.marker_node, null)
mapView.overlays.forEach{
if (it is Marker && it.id == "Node"){
mapView.overlays.remove(it)
}
}
for (i: Int in road.mNodes.indices){
val node: RoadNode = road.mNodes[i]
val nodeMarker: Marker = Marker(mapView)
nodeMarker.position = node.mLocation
nodeMarker.icon = nodeIcon
nodeMarker.title = "Passo $i"
nodeMarker.id = "Node"
mapView.overlays.add(nodeMarker)
nodeMarker.snippet = node.mInstructions
nodeMarker.subDescription = Road.getLengthDurationText(context,node.mLength, node.mDuration)
// var icon: Drawable = resources.getDrawable(R.drawable.ic_continue)
// nodeMarker.image = icon
}
}