google maps in android - android

I am a new user of google maps API in android OS. I have made a small application in which i am using google maps. I want to add a functionality that when i double click (multi touch) on a map the map should zoom in. IS there anybody who has an idea how to do this or if it is possible please provid a code example.
Thanks in advance.
BR,
SilentCoders

I've done something like this in an app using maps api. Although I did this in an overlay item, the principle should be the same.
You could try using TouchListener and GestureDetector to detect the touch events and such.
Note that this is not all actual working code, you need to adopt it so it fits into your implementation.
...
class MyDetector extends SimpleOnGestureListener {
#Override
public boolean onDoubleTap(MotionEvent event) {
mapView.getController().zoomInFixing((int) event.getX(), (int) event.getY());
return super.onDoubleTap(
}
}
// maybe do this in your init or something
GestureDetector gDetector = new GestureDetector(new MyDetector());
mapView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return gDetector.onTouchEvent(event);
}
});
Something like that "should" work :)

Related

onTouch method does not work

I am using onTouch method for doing some works. At first step, I want to show currentX value. However, my code does not work at all. How I resolve this issue?
public boolean onTouch(View view, MotionEvent event) {
int currentX = (int) event.getX();
if(event.getAction() == MotionEvent.ACTION_MOVE) {
Log.d("mesage:",currentX+"");
}
return true;
}
check out this link:
Detecting Common Gestures
You have there snippet like this:
View myView = findViewById(R.id.my_view);
myView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// your stuff
return true;
}
});
do you register your listener for a view? is it separated listener or implemented in Activity or other? is it MotionEventCompat or built in? we need more code...
but you said that you need to recognize "fingers to the right side". look in my link for gestures and "Detecting All Supported Gestures" or "Detecting a Subset of Supported Gestures". onFling method is what you want (right/left you can regonize by velocityX>0 or <0)
edit:
in your activity_main you should have more views. you also may set id for main viewGroup (LinearLayout/RelativeLayout?), which is in whole Activity (Screen) and get this view in findViewById, then setOnTouchLister for this particular view. but like I said above probably you need Gesture

Pan Gesture Recognizer For Android?

I'm replicating my IOS App that heavily uses Pan Gesture Recognizer to Android and I couldn't find similar
Gesture recognizer. Is there such thing?
any direction is appreciated thanks
Android comes out of the box with two classes that recognize gesture. One is GestureDetector and the other is ScaleGestureDetector.
Unlike, ios, the basic gesture detector framework is limited - you can't specify dependencies, do conflict resolution or configure them by specifying touch points etc like you can in ios's UiGestureRecognizer class.
To answer your question, pan can be detected using the GestureDetector. Here is a snippet:
PanGestureListener listener = new PanGestureListener();
GestureDetector detector = new GestureDetector(context, listener);
class PanGestureListener extends GestureDetector.SimpleOnGestureListener {
#Override
public boolean onScroll(MotionEvent e1,
MotionEvent e2,
float distanceX,
float distanceY) {
//YOUR "pan handler"
return true;
}
}
Now in your onTouch method just forward all the calls to detector.onTouch like this:
#Override
public boolean onTouchEvent(MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
I think what you're looking for is GestureDetector. I'm not very familiar with iOS's Pan Gesture Recognizer, but I think it does't work exactly the same way in Android. See the developer guide topic Using Touch Gestures for info on how to use the class.

Identifying double tap on an image view [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to implement doubletap on imageview’s onclick?
In my application I have a Relative layout with three image views.
In the activity I have implemented the simplegesturelistener for getting the swipe to work. Because of this i had to override the onDoubleTap method as well.
My problem is that I want to use the double tap event to zoom out the image from the image view on which the double tap happened (Need to recognize one of the three image views on the layout).
Is there a way to achieve this in the current scenario?
You can refer below code
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
Here I have used Gesture for swipe functionality, and I also have webview in layout in which swipe should work.
So webview's scroll and swipe both should work i have added below methods. Mainly this method is important to add dispatchTouchEvent
#Override
public boolean onTouchEvent(MotionEvent event) {
return (gestureDetector.onTouchEvent(event) || super
.onTouchEvent(event));
}
#Override
public boolean dispatchTouchEvent(MotionEvent e) {
super.dispatchTouchEvent(e);
return gestureDetector.onTouchEvent(e);
}

Android - How to disable horizontal scroll in google mapview?

I am using google MapView in my application and set the zoom level to 2 so that the world map with continent names are visible. Now I want to disable horizontal scrolling. Can any one share some idea on how to do it ?
Just got an idea. Using MotionEvent.AXIS_* flags.
#Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_AXIS_...) {
// ...
}
return sper.onTouchEvent(event);
}
Look at AXIS_HSCROLL, AXIS_VSCROLL, AXIS_X, AXIS_Y, AXIS_Z: Documentation

Disable pan/zoom in com.google.android.maps.MapView

How can i disable the panning/zooming functionality of a MapView (not the zoom controls, i want a wholly static map)?
I've also noticed that touching the map doesn't seem to trigger the MapView onClickListener, could anyone elaborate why?
For version 2 of the Google Maps API for Android, this is the way:
map.getUiSettings().setScrollGesturesEnabled(false);
This is gauranteed to work
mapView.getMap().getUiSettings().setAllGesturesEnabled(false);
Use android:clickable="false" in your layout file.
Please use Overlay to get the tap event on the map
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/Overlay.html
I had the same question and the following solution is the best one I could find and that fulfilled my requirements:
mapView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getPointerCount() > 1) {
return true;
}
return false;
}
});
As posted by Alexander Stolz here:
How to disable pinch in Android MapView
And here is the reason:
It does not disable clicking on the mapView completely - it only grabs & prevents two-finger gestures (for zooming you need two fingers) - tapping on the map (for instance on Overlays) still works.
this is the right way
#Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
switch (ev.getAction()&MotionEvent.ACTION_MASK)
{
case (MotionEvent.ACTION_DOWN):
{
// do what you want
// you may scroll map where you want
// don't use 'break', the same in case pointer events;
//break;
return true;
}
}
// 'super' go to the mapView procedures and scroll map in own algorithm
return super.dispatchTouchEvent(ev);
}
on your onMapReady method, add these code lines
gMap.getUiSettings().setZoomGesturesEnabled(false);
to disable all the guesures
gMap.getUiSettings().setAllGesturesEnabled(false);
happy coding :)

Categories

Resources