开发者

ItemizedOverlay hitTest

I'm using this method to detect whether someone clicks on an overlay. Now everything works except for that the click area is too small. So I looked at the api which said "See if a given hit point is within the bounds of an item's marker. ".

I made my bounds bigger like this:

Log.d("debug", "Marker propertie 1: "  + marker.getBounds());   //output:Marker propertie 1: Rect(0, 0 - 0, 0)

Rect square = new Rect(0, 0, 200, 200);
m开发者_如何学编程arker.setBounds(square);
Log.d("debug", "Marker propertie 2: "  + marker.getBounds());   //output:Marker propertie 2: Rect(0, 0 - 200, 200)
if (hitTest(item, marker, x-p.x, y-p.y)) {
//...
}

But both ways of changing its bounds doesn't change the click-area. Can someone hint me how I can increase the clickarea of my drawables?


This is the google maps api? If you want to extend the bound you can overide the hitTest of your extended itemizedOverlay to something like this.

@Override
protected boolean hitTest(OverlayItem overlayItem, Drawable drawable, int x, int y) {
    Rect bounds = drawable.getBounds();
    int newLeft = (int) (200 * ((double)bounds.left / (double)bounds.width())  ) ;
    int newTop = (int) (200 * ((double)bounds.top  / (double)bounds.height()) );
    Rect square = new Rect(newLeft, newTop, 200, 200);
    return square.contains(x, y);
}

Just tested on a map I have seems to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜