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 .
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 .
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() }