1

I need to zoom when double tapping. Why doesn't this work? I worked on it for long time which has no result. No touch event is recognized

public class MyMapActivity extends MapActivity implements OnGestureListener{
private MapView mapView;

@Override
public void onCreate(Bundle savedInstanceState) {

requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView)findViewById(R.id.mapView);
mGestureDetector = new GestureDetector(this,this);
detector.setOnDoubleTapListener(new OnDoubleTapListener(){
    @Override
public boolean onDoubleTap(MotionEvent e) {
 int x = (int)e.getX(), y = (int)e.getY();;  
 Projection p = map.getProjection();  
 map.getController().animateTo(p.fromPixels(x, y));
 map.getController().zoomInFixing(x, y);  
 return false;
}

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    return false;
}

    });
}
@Override
public boolean onTouchEvent(MotionEvent me) {
this.mGestureDetector.onTouchEvent(me);
return super.onTouchEvent(me); 
}
ChanChow
  • 1,346
  • 7
  • 28
  • 57
  • Is this a typo? You have specified `implements OnDoubleTapListener, OnDoubleTapListener` i.e. `implements OnDoubleTapListener` twice. – Code Poet Oct 28 '12 at 06:29
  • possible duplicate of [Double Tap -> Zoom on Android MapView?](http://stackoverflow.com/questions/2691235/double-tap-zoom-on-android-mapview) – RichardTheKiwi Oct 28 '12 at 23:51
  • I would agree its a duplicate. But my question is to find the error. So, try to please help instead of telling me its duplicate. I am working for 3 days on this. – ChanChow Oct 29 '12 at 01:23
  • can some one give me the solution to my problem please – ChanChow Nov 06 '12 at 10:43

2 Answers2

2

see this tutorial, it have the complete how to or see the similar questions on stackoverflow here and here.

Community
  • 1
  • 1
ademar111190
  • 14,215
  • 14
  • 85
  • 114
  • The modified code it the one employed from the links you provided which doesn't work for me for some reason. Can you please pick the one – ChanChow Oct 28 '12 at 05:53
  • @user1494754 you're implementing the OnDoubleTapListener on your activity class, in all examples above the people are using a custom class extended mapview to it and they are using OnGestureListener too. try create a new project to test and follow the tutorial step by step. ;) – ademar111190 Oct 28 '12 at 06:09
  • It shouldn't make any difference. I followed this from a one tutorial and it should work. But not able to find the culprit – ChanChow Oct 28 '12 at 06:23
  • @user1494754 you not following the tutorial, in your code you're using a mapview, see the tutorial again. – ademar111190 Oct 29 '12 at 01:00
  • yes. I am working on google maps api. What does that mean. Did you get it, Please let me know – ChanChow Oct 29 '12 at 01:38
  • @user1494754 see it on tutorial 'public class MyMapView extends MapView' – ademar111190 Oct 29 '12 at 13:32
  • It doesn't make any difference. what you are saying is just inheriting methods – ChanChow Nov 06 '12 at 10:00
  • hey..today I recognized that double tap works suddenly and when I looked around the things I found what you are saying. Double tap works for activity but not the mapview. I am not able to tap on the map but when I click on the title bar it works. So, now I understood what you meant by extends mapview. Thanks for that. – ChanChow Nov 06 '12 at 22:56
2

Try having a look at the MapView Ballons library which has support for double tapping to zoom and more! It is really good and easy to use and integrate with a project. MapView Ballons

SquiresSquire
  • 2,404
  • 4
  • 23
  • 39
  • I checked the syntax and it looks the similar to what I have used. Can you please correct me – ChanChow Oct 28 '12 at 20:02
  • It would be a lot easier just to import the library into your project, then add a tapcontrolled mapview. – SquiresSquire Oct 28 '12 at 20:21
  • Thanks. But it would be helpful for me if you can tell me the problem in my code. So, I could learn something. It seems perfect leaving me no clue and I would really appreciate your help – ChanChow Oct 28 '12 at 22:35