How to make Google make in center when using double Tap and pinch to zoom in android? -


i have search google map center while zooming using double tap , pinch zoom. have found 1 solution here, double tap zoom solution.

touchablewrapper

 public class touchablewrapper extends framelayout {      gesturedetectorcompat mgesturedetector;       public touchablewrapper(context context) {         super(context);         mgesturedetector = new gesturedetectorcompat(context, mgesturelistener);     }       private final gesturedetector.simpleongesturelistener mgesturelistener             = new gesturedetector.simpleongesturelistener() {         @override         public boolean ondoubletap(motionevent e) {             log.e("gesturedetector", "executed");             //notify event bus (i using otto eventbus of course) have received double-tap event on map, inside event bus event listener             eventbus_singleton.getinstance().post(new eventbus_poster("double_tapped_map"));              return true;         }     };      @override     public boolean onintercepttouchevent(motionevent ev) {         mgesturedetector.ontouchevent(ev);         return super.onintercepttouchevent(ev);     }   } 

i have used otto event trigger.

public class eventbus_singleton {      private static final bus bus = new bus();      public static bus getinstance() {         return bus;     }      public eventbus_singleton() {     }      public void post(string s) {         bus.post(s);     } } 

eventbus_poster

public class eventbus_poster {     public final string string;      eventbus_poster(string string) {         this.string = string;     } } 

in map activity have used event receiving method zoom map on same location.

 @subscribe     public void eventbus_singleton(eventbus_poster event) {         log.e("eventbus_singleton", "executed");         if (event != null && event.string.equals("double_tapped_map")) {             if (mapfragment != null) {                 mapfragment.getmap().getuisettings().setzoomgesturesenabled(false);                 mapfragment.getmap().getuisettings().setrotategesturesenabled(false);                  mapfragment.getmap().setoncamerachangelistener(new googlemap.oncamerachangelistener() {                     @override                     public void oncamerachange(cameraposition cameraposition) {                         latlng lng = cameraposition.target;                         log.e("latlng", "" + lng);                     }                 });                 mapfragment.getmap().animatecamera(cameraupdatefactory.zoomin(), 400, null);             }          }     } 

i have tried use scalegesturedetector.simpleonscalegesturelistener make pinch zoom didnt work , sometime lagging. can me make pinch zoom in google map?

well, i've found when trying this, successful pinch-to-zoom involves both velocity , scale condition. velocity measured determine whether want zoom depending on how fast moved 2 fingers away or closer each other, can try inside google maps , inside uber's app, can keep moving fingers away or closer each other not trigger zoom in/out event on map!

so involves velocity when trying determine full pinch gesture. second of course need scale also, , i've printed out scale value , always smaller 1.0 when start pinching zoom out , larger 1.0 when start pinching zoom in.

combination of these 2 better results, see velocity first i'd say

private final scalegesturedetector.onscalegesturelistener mscalegesturelistener         = new scalegesturedetector.simpleonscalegesturelistener() {     /**      * active focal point in terms of viewport. local      * variable kept here minimize per-frame allocations.      */      float startingspan;     float startfocusx;     float startfocusy;      @override     public boolean onscalebegin(scalegesturedetector scalegesturedetector) {         startingspan = scalegesturedetector.getcurrentspan();         startfocusx = scalegesturedetector.getfocusx();         startfocusy = scalegesturedetector.getfocusy();          return true;     }      @override     public boolean onscale(scalegesturedetector scalegesturedetector) {         float scale = scalegesturedetector.getcurrentspan() / startingspan;          mvelocitytracker.computecurrentvelocity(1000);          log.d("velocity", "x vel : " + mvelocitytracker.getxvelocity());         log.d("velocity", "y vel : " + mvelocitytracker.getyvelocity());          if (scale <= 1.0) {             eventbus_singleton.getinstance().post(new eventbus_poster("pinched_map", "out"));         } else {             eventbus_singleton.getinstance().post(new eventbus_poster("pinched_map", "in"));         }          return true;     } }; 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -