I am trying to insert more polylineoptions in my map, I would like to put 3 conditions and based on them choose the color of the line. With the code I have I can see the correct map portion, but it doesn't show any lines. Anyone know how to help me?
override fun onMapReady(p0: GoogleMap?) {
googleMap = p0
val bc = LatLngBounds.Builder()
val points: ArrayList<LatLng> = ArrayList()
val locations: ArrayList<Location> = ArrayList()
val polypoint : ArrayList<PolylineOptions> = ArrayList()
googleMap!!.setOnMapLoadedCallback {
foo.bar.forEachIndexed {fooIndex, step ->
bar.asd.forEachIndexed { index, location ->
asd.add(location)
for (point: Location in asd) {
val list = foo.bar[fooIndex]!!.asd.chunked(2)
if (index < list.size) {
val value = getValue()
if (value >= 0 && value < 70) {
googleMap!!.addPolyline(PolylineOptions()
.add(LatLng(point.latitude, point.longitude), LatLng(point.latitude, point.longitude))
.width(14f)
.color(Color.GREEN))
} else if (value >= 70 && value < 150) {
googleMap!!.addPolyline(PolylineOptions()
.add(LatLng(point.latitude, point.longitude), LatLng(point.latitude, point.longitude))
.width(14f)
.color(Color.YELLOW))
} else {
googleMap!!.addPolyline(PolylineOptions()
.add(LatLng(point.latitude, point.longitude), LatLng(point.latitude, point.longitude))
.width(14f)
.color(Color.RED))
}
}
}
points.add(LatLng(location.latitude, location.longitude))
bc.include(LatLng(location.latitude, location.longitude))
}
}
if (points.size != 0) {
if (points.size < 2) {
bc.include(points[0])
bc.include(points[points.size - 1])
}
googleMap!!.moveCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 60))
}
}
}