Я хочу сделать фокус в картах для каждого элемента RecyclerView
У меня есть главная страница приложения с RecyclerView, все элементы записаны в ArrayList
private fun setItem(): ArrayList<Item> {
//добавление элементов в RecyclerView
var arrayList: ArrayList<Item> = ArrayList()
arrayList.add(Item(R.drawable.koscmos,"")
arrayList.add(Item(R.drawable.bridge,"Latter")
return arrayList
}
и есть вторая активность
В которой есть кнопка к карте. При переходе к гугл картам есть маркер. И вот самый главный вопрос. Я хочу сделать так, чтобы для каждого объекта RecyclerView при переходе был и свой маркер (это я сделать смог), и приближение к этому маркеру.
Все данные передаются во вторую активность через OnСlick
val intent= Intent(this, secondAct::class.java)
intent.putExtra("item", item?.get(position))
startActivity(intent)
Все данные находятся в item
Если у кого-то есть опыт работы с гугл картами или хоть какие-то идеи, рад выслушать.
Код гугл карт:
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
private fun bitmapDescriptorFromVector(context: Context, vectorResId: Int): BitmapDescriptor? {
return ContextCompat.getDrawable(context, vectorResId)?.run {
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
val bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
draw(canvas)
BitmapDescriptorFactory.fromBitmap(bitmap)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
mMap.setMinZoomPreference(10.0f)
mMap.setMaxZoomPreference(20.0f)
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
val success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, R.raw.mapstyle))
if (!success) {
Log.e("MapsActivity", "Style parsing failed.")
}
} catch (e: Resources.NotFoundException) {
Log.e("MapsActivity", "Can't find style. Error: ", e)
}
val MuzeumOFCosmos = LatLng(54.5173381989551,36.23063585608777)
val zoomLevel = 14.3f
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(MuzeumOFCosmos, zoomLevel))
mMap.addMarker(MarkerOptions().position(MuzeumOFCosmos).icon(bitmapDescriptorFromVector(baseContext, R.drawable.drw)))
}
