Android: ItemizedOverlay onTouchEvent and onTap overlapping

心不动则不痛 提交于 2019-11-29 00:40:25

I had exactly the same issue, my onTouchEvent added a marker to a map, and wanted it to show information about that marker when the user clicks on it, it worked but it also added another marker on top of it.

So what I did was not use onTouchEvent but do everything in onTap(int index) and onTap(Geopoint p, MapView mapView) like so:

public boolean onTap (final GeoPoint p, final MapView mapView){
    boolean tapped = super.onTap(p, mapView);
    if (tapped){            
        //do what you want to do when you hit an item           
    }           
    else{
        //do what you want to do when you DON'T hit an item
        }                   
    return true;
}

//Return true in order to say that the listener has correctly taken the event into account 
@Override
protected boolean onTap(int index) {
    return true;
}

Regards,

Tom

Naresh R

If you are updating the previous overlay, set isFirst=true; in the call to `remove() to remove the overlay in question.

In the onTap() call, use

if(isFirst)
{
    isFirst=false;
} else{
    // the actual onTap() comes here
}

I hope that it'll work the same if isFirst=true is set in the onDraw() as well.

I think that the problem is fundamentally that the onTap is a particular onTouchEvent, so if you write both in the overlay they are both fired when you touch the map

You could try to add a new overlay item in one of the touch events you implemented in your mapActivity and leave the onTap event in the overlay as it is right now

it might work this way but you have to try, I'm not sure!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!