Touchable Google Maps in Android

Google Maps Android API v2 is a great library for Android developers to create maps application. It is very clear and easy to use. Creating map items and events are very easy. But, when i was working on it, there is no touch event on the map. What happens if user tap the map, zoom the map, etc. What is the new position of camera? What is the new zoom level?

I have created two classes to handle touch event on Google Maps.
    public class TouchableWrapper extends FrameLayout
and
    public class TouchableSupportMapFragment extends SupportMapFragment
TouchableWrapper class is responsible about touch events, and TouchableSupportMapFragment class is our new MapFragment which is extends from SupportMapFragment and it has TouchableWrapper.

How to use them?
  1. Add TouchableWrapper and TouchableSupportMapFragment to your project. You can find them in the sample project.
  2. Replace class property of your SupportMapFragment with TouchableSupportMapFragment in your layout.
        
        
        
    
  3. Implements TouchableWrapper.TouchActionDown and TouchableWrapper.TouchActionDown to your activity.
    import com.muratonnet.map.TouchableWrapper.TouchActionDown;
    import com.muratonnet.map.TouchableWrapper.TouchActionUp;
    
    public class MainActivity extends FragmentActivity 
        implements TouchActionDown, TouchActionUp {
    
        @Override
        public void onTouchDown(MotionEvent event) {
      
        }
    
        @Override
        public void onTouchUp(MotionEvent event) {
      
        }
    
    }
    
That's all. Now, you have events about user taps. You can do whatever you want, when user touch down/up on the map.



You can find source code and sample usage on

Don't forget to set your "API_KEY" in manifest file to run sample project.

2 comments:

Anonymous said...

how do i add markers on map V2

Anonymous said...

I'm unable to find the source Code..!! Can U please help me..

Post a Comment