Locate Zoom Controls (x,y) in MapView?

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Locate Zoom Controls (x,y) in MapView?

Postby mcmatom » Mon Mar 14, 2011 4:32 pm

Hi all,

I apologize in advance for my ignorance. I am a seasoned SW developer but new to Android. I am developing my first Android application (MapActivity) for a friend of mine and have managed to fight my way through a myriad of problems handling gestures, not the least of which was onTap(GeoPoint p, MapView mapView) used to capture a non marker tap in the ItemizedOverlay intercepting every gesture available. I settled on using OnSingleTapConfirmed from DoubleTapListener and handling the marker/non-marker tap logic from there. I have still one issue remaining I cannot seem to solve. OnSingleTapConfirmed apparently is handled before
the built in Zoom Controls, so when I tap in the space where the zoom controls are hidden, I get the non-marker tap behavior in addition to the zoom control becoming visible which is not what I want. I'd like to only see the zoom controls become visible in that case.

I figured I could simply do a hit test on the zoom control rectangle and if I get a hit, simply bail out of OnSingleTapConfirmed with a FALSE return value and let the built in logic take it from there. I am able to get the rectangle for the zoom controls using the MapView's getZoomButtonsController() and then calling getZoomControls() from there. I then call getHitRect to get the target touch area. The problem
I am having is determining where the Zoom Control's starting x,y position isrelative to the MapView.
Once I can determine that, I can apply the offset to my hit rectangle and simply do a contains check.

It may be very simple and likely is and I can't see it (I've been looking at this too long and think I can't see the forest for the trees), but I'm spinning my wheels at this point.

Does anyone know how to find the built in zoom control's starting x,y position relative to the MapView? If there is a simpler solution to ensuring the ZoomControls will still function properly when handling tap
gestures, I am open to suggestions. I appreciate any advice anyone would be willing to offer.

Thanks in advance.

Tom McManus

UPDATE: I have managed to get this working, but it still has a "hacky" feel to me since it is completely reliant on the placement of the zoom controls forever being at the bottom of the screen. I am open to any suggestions on
how to handle this more appropriately. For anyone interested, the code snippet placed into OnSingleTapUpConfirmed follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     ZoomButtonsController zBC = mView.getZoomButtonsController();
  2.     View zcView = zBC.getZoomControls();
  4.     int iMapHeight = mView.getHeight();
  6.     Rect zoomHit = new Rect();
  7.     zcView.getHitRect(zoomHit);
  9.     zoomHit.top = iMapHeight - zcView.getHeight();
  10.     zoomHit.bottom = iMapHeight;
  12.     RectF rectFloat = new RectF(zoomHit);
  13.     if (rectFloat.contains(e.getX(),e.getY())) {
  14.         return false;
  15.     }
Parsed in 0.011 seconds, using GeSHi
Once Poster
Once Poster
Posts: 1
Joined: Sat Sep 25, 2010 4:05 am


Re: Locate Zoom Controls (x,y) in MapView?

Postby magi111 » Thu Aug 18, 2011 6:37 am

Wow its really nice article...
Yes i agreed with your discussion...thanks for giving this exact reasons...

Wheels Miami
Posts: 6
Joined: Thu Aug 18, 2011 6:36 am

Re: Locate Zoom Controls (x,y) in MapView?

Postby Kabir121 » Sat Aug 20, 2011 7:11 pm

Hi Everyone,

I want to make a map that on overlay click give the images of contacts or just show me any stored images.
Can anyone Help me....... :roll:
Once Poster
Once Poster
Posts: 1
Joined: Sat Aug 20, 2011 6:44 pm


Return to Map Problems

Who is online

Users browsing this forum: No registered users and 4 guests