![](https://downtips.com/wp-content/uploads/2024/01/android-studio-logo-1.png)
How to disable the marker click event in Android Studio
Admin
- 0
DownTips gives you the best solution how to disable the marker click event.
It is clear by this point 3 years later, that there is no way to let marker clicks pass through to be handled by the map itself (OnMapClickListener). Markers will always intercept this event, although you can disable the default behavior from the click (as the answer above shows). The following is posted in case it can help someone still needing a better solution.
To work around this limitation, there are two options. I have implemented both and can clean up and share the code on request.
1.) Create a GroundOverlay Bitmap that has the waypoints that you don’t want to handle painted onto it. You use GoogleMap’s Projection object to convert from screen Points to LatLng and calculate where to position the Bitmap to have the waypoints appear in the correct place. It’s fairly complicated to handle rotation, map padding, and a few other issues. As you zoom in, the waypoint markers do grow in size, and then in the onCameraIdle event, you re-create the bitmap and re-position the GroundOverlay if necessary. This is the method I am using in production. Panning, rotating, and zooming are all super smooth, and as Ground Overlays can be set to handle or not handle taps, it solves the problem. I was not able to figure out how to make this work with tilt. The waypoints themselves do not stay facing North during rotation but can be rotated upright when the GroundOverlay is re-created. There is a short pause/non-responsiveness of the map after the onCameraIdle causes the re-creation of the ground overlay.
2.) Create a View object that covers the entire screen, and paints the waypoint markers in the onDraw method of the view. Again, use the GoogleMap’s projection object to calculate where to paint the markers. Call invalidate() on the view when in the onCameraMove event, so the markers are re-drawn at their new screen positions. The main advantage of this is simplicity. Rotation, tilt, and map padding offsets are all handled for you. The main disadvantage is that if you invalidate every onCameraMove event, it is a bit too CPU intensive (I presume) and the map panning/zooming can become choppy. If you invalidate every 3 or 5 move events, then the waypoints appear to be bouncing as you pan/zoom as they aren’t repainted in their new position frequently enough. There is no delay at the end of the map move, though. Ultimately, with 100-200 waypoints on the map, the “while-panning” performance issues were too noticeable for me.
Hope this information helps you.
If you need some code help Here is the code.
mMap.setOnMarkerClickListener( new OnMarkerClickListener()
{
@Override
public boolean onMarkerClick ( Marker marker )
{
// do nothing
return false;
}
});