0

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 that 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?

user756212
  • 522
  • 5
  • 16

3 Answers3

1

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;

} 
Digo
  • 11
  • 1
0

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") {
Dayerman
  • 3,973
  • 6
  • 38
  • 54
  • I am not 100% sure what you are suggesting here, this code looks like it would determine which marker was clicked on in a view. However where/when is this event being called? – user756212 May 23 '11 at 16:22
  • I don't see this signature in the API's – user756212 May 23 '11 at 16:23
  • Nevermind, I found it... This is an override in the overlay got you. However I am still confused why the onTap is not being fired like the API says it should. – user756212 May 23 '11 at 16:25
  • Hi, It will be launch each time the use touch the screen. Are u extending your class from MapActivity? Is a class of the GoogleMap API for Android, and contains the event handler. – Dayerman May 23 '11 at 22:31
  • Yes, I am extending MapActivity, and as I stated, for touch events everything is working beautifully... its the trackball click on the Overlay Item that is just not happening. – user756212 May 24 '11 at 06:08
  • Your suggestions unfortunately have not helped, when I attempt to add the onTouchEvent in the mapActivity, it never fires either, this I assume is due to the map-verlay-manager extentions handling them... I am just confused on this function. The docs say onTap should be firing when the user clicks on the trackball over an overlayItem, yet it just doesn't happen. When the center is NOT over an overlay item the click is fired and reaches the onTrackBallEvent() method no problems. – user756212 May 24 '11 at 06:14
  • The DPAD shows the same behaviors, the KEYEVENT shows up in the activity no problem when not over an overlay, but when over an overlay, NOTHING when the center button is clicked. On a side note, how does one ZOOM a mapview using the trackball in the emulator? I am about to just abandon trackball support, at least for version 1.0 of my app. – user756212 May 24 '11 at 06:14
  • Have a look here: http://groups.google.com/group/android-developers/browse_thread/thread/5696833388d162fd – Dayerman May 24 '11 at 08:15
  • Okay, I think I figured out WHY I never see the trackball click event when over an OverlayItem, but not sure exactly what to do to fix it. – user756212 May 24 '11 at 14:59
  • I am using teh ManagedOverlay class (from the mapview-overlay-manager extentions) which extendes ItemizedOverlay. Now this class has the following: @Override public boolean onTrackballEvent(MotionEvent event, MapView mapView) { return super.onTrackballEvent(event, mapView); } So I am guessing that this is grabbing the click event and consuming so it never gets passed up to the MapView. I suppose I could extend this class and override, but it would require overriding other classes as well to acheive. This seems excessive work for this. – user756212 May 24 '11 at 15:06
  • Although reading the documentation, this should just fcall the OnTrackBallEvent() on the ItemizedOverlay which according to the documentation should return false, so my code should be getting this event, but it just doesn't. I am admittedly beyond confused at this point. – user756212 May 24 '11 at 17:18
0

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

Basil
  • 2,163
  • 2
  • 16
  • 25
  • Thanks, for the suggestion, but this isn't my problem. – user756212 May 24 '11 at 16:14
  • The overlays appear fine, the problem is that when in trackball mode, and over an overlay, the trackball click event never seems to fire.. or at least never seems to reach my code.. Its as thought the trackball click is not being passed up the view chains. IE the managedOverlay is consuming it, when its on an overlay item, and I don't have direct or simple access to extend/override this class. – user756212 May 24 '11 at 16:16