-2

I want to reduce the. touch area of marker in focus. While click area is too big, I want to short the click area of marker on google map.

I am new to map, I want to know how could we reduce the padding of marker in focus in android .

1 Answers1

0
  • first I tried. to add one overlay inside xml <View android:id="@+id/transparentOverlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" />

     then inside onMapReady, I implemented this code -  
    
     binding.transparentOverlay.setOnClickListener { view ->
                 val mapClickPoint = Point(view.x.toInt(), view.y.toInt())
                 val mapLatLng = map.projection.fromScreenLocation(mapClickPoint)
                 if (this::carMarker.isInitialized) {
                     if (isPointInMarkerClickableArea(carMarker, mapLatLng)) {
                         // The click was within the custom clickable area of the marker
                         // Handle the marker click here
                         markerClickAction(carMarker)
                     }
                 }
             }   private fun isPointInMarkerClickableArea(marker: Marker, clickLatLng: LatLng): Boolean {
         // Calculate the distance between the marker's position and the clickLatLng
         // If the distance is within a certain threshold, consider it a click on the marker
         val distanceThreshold = 50 // in pixels, adjust as needed
         val markerPosition = marker.position
         val markerScreenPosition = map.projection.toScreenLocation(markerPosition)
         val clickScreenPosition = map.projection.toScreenLocation(clickLatLng)
         val distance = Math.sqrt(Math.pow((markerScreenPosition.x - clickScreenPosition.x).toDouble(), 2.0) +
     Math.pow((markerScreenPosition.y - clickScreenPosition.y).toDouble(),
     2.0))
         return distance <= distanceThreshold }  private fun markerClickAction(carMarker: Marker) {
         // Implement your action when the marker is clicked
         // For example, show an info window, navigate to a detailed view, etc.
         Toast.makeText(this, "Click on marker: ${carMarker.title}", Toast.LENGTH_SHORT).show() }
    
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 06 '23 at 07:58