Android 安卓:谷歌地图在一个可观察列表中选择标记
我有下面的代码,我想在observable中点击标记,并在对话框中显示信息,我的问题是当我显示信息时,只显示最后一个对象Android 安卓:谷歌地图在一个可观察列表中选择标记,android,google-maps,kotlin,Android,Google Maps,Kotlin,我有下面的代码,我想在observable中点击标记,并在对话框中显示信息,我的问题是当我显示信息时,只显示最后一个对象 viewModel.GetUserInfo().observe(this, Observer { user -> val latLng = LatLng(user.Latitude.toDouble(), user.Longitude.toDouble()) p0!!.addMarker(
viewModel.GetUserInfo().observe(this, Observer { user ->
val latLng = LatLng(user.Latitude.toDouble(), user.Longitude.toDouble())
p0!!.addMarker(
MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location_friends))
)
p0.setOnMarkerClickListener(object: GoogleMap.OnMarkerClickListener {
override fun onMarkerClick(p0: Marker?): Boolean {
var bottomSheetDialog = view?.let { BottomSheetDialog(it.context, R.style.BottomSheetDialogTheme) }
var bottomView = LayoutInflater.from(context)
.inflate(R.layout.window_bottom_preview, view?.findViewById(R.id.windows_previewContainer))
var textName_Age = bottomView.findViewById<TextView>(R.id.textName_Age)
var name = user.UserName
bottomSheetDialog!!.setContentView(bottomView)
bottomSheetDialog.show()
return true
}
})
println("$user")
})
viewModel.GetUserInfo().observe(这个,观察者{user->
val latLng=latLng(user.Latitude.toDouble(),user.Longitude.toDouble())
p0!!.addMarker(
标记选项()
.位置(车床)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location\u friends))
)
p0.setOnMarkerClickListener(对象:GoogleMap.OnMarkerClickListener{
重写MarkerClick(p0:Marker?):布尔值{
var bottomSheetDialog=view?.let{bottomSheetDialog(it.context,R.style.BottomSheetDialogTheme)}
var bottomView=LayoutInflater.from(上下文)
.充气(R.layout.window\u bottom\u preview,view?.findViewById(R.id.windows\u previewContainer))
var textName\u Age=bottomView.findviewbyd(R.id.textName\u Age)
var name=user.UserName
bottomSheetDialog!!.setContentView(bottomView)
bottomSheetDialog.show()
返回真值
}
})
println(“$user”)
})