Google Map Marker Clickable Area

I use this example: https://github.com/galex/android-mapviewballoons

My problem is that the clickable area is wider than the marker itself. For example, my Google Map marker is 25x25, then the click zone will expand to 70x70. This is a big problem for overlapping markers. enter image description here

When I clicked on the tip of this arrow, onTap is activated, although the retraction area is far from the marker.

Please help me. Thanks.

+7
source share
2 answers

This is the default value of ItemizedOverlay . 25x25 pixels are generally not a suitable area for most human fingers.

You must override the hitTest() method if you want to change the way that an overlay element is hit.

+1
source

For debugging:

Try using TouchDelegate for presentation, you can specify Touch rect to get View

An example showing how to use TouchDelegate :

 public class TouchDelegateSample extends Activity { Button mButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.touch_delegate_view); mButton = (Button)findViewById(R.id.delegated_button); View parent = findViewById(R.id.touch_delegate_root); // post a runnable to the parent view message queue so its run after // the view is drawn parent.post(new Runnable() { @Override public void run() { Rect delegateArea = new Rect(); Button delegate = TouchDelegateSample.this.mButton; delegate.getHitRect(delegateArea); delegateArea.top -= 200; TouchDelegate expandedArea = new TouchDelegate(delegateArea, delegate); // give the delegate to an ancestor of the view we're delegating the // area to if (View.class.isInstance(delegate.getParent())) { ((View)delegate.getParent()).setTouchDelegate(expandedArea); } } }); } } 

hitTest()

Make sure that this hit point is within the element’s marker. Override to change the way an item is validated. The hit point refers to the boundaries of the marker. The default implementation simply checks to see if the hit point is within the visible boundaries of the marker.

-one
source

All Articles