我正在尝试使用自定义图标和颜色放置标记。目前在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
我希望当我单击标记时,应该显示单击该标记的祝酒词。但是什么也不会发生,只是将标记居中。
答案 0 :(得分:0)
我能够使您的代码正常工作,但是我将侦听器添加到onMapReady:
arr = line.split('> <')
arr[0] = arr[0] + '>'
arr[1] = '<' + arr[1]
调用.getMapAsync()后会调用此方法