Place Ground Overlay and show toast if clicked
If user clicks a ground overlay, show a toast message.
1️⃣ Declare variables for a ground overlay to be placed on the map. Ensure that the clickable property is set to true.
val mGOLatLng = LatLng(25.12299, 121.46196) val mGOMapOpt = GroundOverlayOptions() .image(BitmapDescriptorFactory.fromResource(R.drawable.SampleImage)) .position(mGOLatLng, 100f) .clickable(true)
2️⃣ Place the ground overlay on the map, and add a tag to identify each placement.
mMap.addGroundOverlay(mGOMapOpt)?.tag = "haha"
3️⃣ Initialize setOnGroundOverlayClickListener to listen for user clicks, then show a toast message if the clicked overlay matches the tag.
mMap.setOnGroundOverlayClickListener { if (it.tag == "haha") { Toast.makeText( applicationContext, "This is a haha message", Toast.LENGTH_SHORT ).show() } }
→