【发布时间】:2019-09-23 08:24:46
【问题描述】:
我正在尝试使用自定义图标和颜色放置标记。目前在 kotlin for android 工作。我正在尝试按照 google 文档中的说明在点击侦听器上设置标记。但是点击时什么都没有发生。
重写 onMarkerClick 函数并尝试获取该标记的标记,因为我存储在该标记中,在此之前我尝试使用 .equal 方法来测试标记是否等于该事件标记
override fun onMarkerClick(marker: Marker): Boolean {
// Retrieve the data from the marker.
var clickCount = marker.tag as Int?
// Check if a click count was set, then display the click count.
if (clickCount != null) {
clickCount = clickCount!! + 1
marker.tag = clickCount
Toast.makeText(
this,
marker.title +
" has been clicked " + clickCount + " times.",
Toast.LENGTH_SHORT
).show()
}
// Return false to indicate that we have not consumed the event and that we wish
// for the default behavior to occur (which is for the camera to move such that the
// marker is centered and for the marker's info window to open, if it has one).
return false
}
mMap = googleMap
val streetRight = mMap.addMarker(
MarkerOptions().position(
LatLng(
-xx.xxxxx,
xxx.xxxxxx
)
).icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_street_view_person))
)
val streeTop = mMap.addMarker(
MarkerOptions().position(
LatLng(
-xx.xxxxx,
xxx.xxxxxx
)
).icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_street_view_person))
)
streeTop.tag = 1
streetRight.tag = 2
我希望当我单击标记时,它应该显示单击标记的祝酒词。但是什么都没有发生,只是将那个标记映射到中心。
【问题讨论】:
-
调试你的代码并在这一行放一个断点`var clickCount = marker.tag as Int?` 如果这行有反应,那么
clickCount是空的。 -
@MahmoudShahoud 是的,它正在反应
标签: android google-maps kotlin google-maps-markers kotlin-android-extensions