开发者

Mapview onTap not firing for OverlayItem onTap

开发者 https://www.devze.com 2023-03-07 15:30 出处:网络
I have a mapview in my app, and everything is working fabulously with touchEvents. However to maximize usership of the App, I have been trying to add trackBall interface functionality as well and am

I have a mapview in my app, and everything is working fabulously with touchEvents.

However to maximize usership of the App, I have been trying to add trackBall interface functionality as well and am running into a problem.

The trackball properly scrolls the mapView around when it is in focus, however I am unable to get the onTap event to fire when the user has centered on an overlay item.

When I click the mouse button (I am using the emulator) to simulate a click by the trackball user (F6 engaged trackball) nothing happens.. The onTrackBallEvent code never gets fired in this situation, which I would expect given the API docs say that the onTap should be fired in this instance, but it doesn't get fired either.

If I am not centered on an overlayItem I do get the ACTION_DOWN and ACTION_UP events in the onTrackBallEvent, it is only when the map is centered on an OverlayItem tha开发者_如何转开发t the onTrackBallEvent does not get fired. Unfortunately the onTap Events don't get fired either. Obviously the OS is doing something with these clicks when an overlay is under the center of the screen and a user clicks on the trackball, but I will be darned if I can figure out what it is.

Does anyone know what Event I should be looking for?


This is quite an old issue but figured I'd give my 2 cents. For some reason, you need to add an overlay somewhere on the map before the onTap() override can add other overlays where you click. I used:

public boolean onTap(GeoPoint p, MapView mapView) {
    boolean tappedAnOverlay = super.onTap(p, mapView);
    if (tappedAnOverlay) {
        // do your thing if hit an overlay
    }
    else {
        // no overlay found in that location
    }

    MapController mc = mapView.getController();
    mc.animateTo(p);

    return true;

} 


For it works with this. I check if the hit point on the screen matches with some overlay item.

        public boolean onTouchEvent(MotionEvent event, MapView mv) {
        final int action=event.getAction();
        final int x=(int)event.getX();
        final int y=(int)event.getY();

        if(!this.marker.equals(getResources().getDrawable(R.drawable.parada))){
            if (action == MotionEvent.ACTION_DOWN) {
                        for (OverlayItem item : mItems) {
                        Point p = new Point(0,0);                       
                        mv.getProjection().toPixels(item.getPoint(), p);                        
                        if (hitTest(item, marker, x-p.x, y-p.y) && item.getSnippet()!= "parada") {


please try this one. This is used for showing multiple overlays on map view, may be it will solve the problem: https://github.com/donnfelker/android-mapviewballoons

0

精彩评论

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

关注公众号