2016-11-17 4 views
1

編集作業ではない。私は私の問題はGoogleマップAPIのジェスチャーは(ズーム・回転...)

下記の私の答えを見たオリジナルのポスト:
私はマップが含まれているアクティビティを作成しています、ズームやその他のジェスチャー機能を追加することはできません。私はズームインしてタップを倍増することができ、かつ

googleMap.getUiSettings().setAllGesturesEnabled(true); 

これは私のコードである経て、私はズームする+/-記号を追加することができます。

活動のXML(tracking_order.xml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal"> 

<fragment 
    android:id="@+id/mapFragment" 
    class="com.example.OrderMapFragment" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="3" /> 

<FrameLayout 
    android:id="@+id/clientsFragment" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" /> 

OrderMapFragment.java

public class OrderMapFragment extends SupportMapFragment implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener { 

    public static OrderMapFragment newInstance() { 
     OrderMapFragment fragment = new OrderMapFragment(); 
     Bundle args = new Bundle(); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onAttach(Context context) { 
     super.onAttach(context); 
     ((OrderMapFragment.OnOrderMarkerClickListener) context).setMapObject(this); 
     getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(final GoogleMap googleMap) { 
     googleMap.getUiSettings().setZoomControlsEnabled(true); //this one is working 
     googleMap.getUiSettings().setZoomGesturesEnabled(true); //not working 

     googleMap.getUiSettings().setAllGesturesEnabled(true); //not working 
     // ... (removed code used to fetch markers data) 
    } 

    @Override 
    public boolean onMarkerClick(Marker marker) { 
     return listener.filterListByMarker(marker); 
    } 

    public interface OnOrderMarkerClickListener { 
     /** 
     * Action to be taken when a marker has been clicked 
     * 
     * @param marker 
     * @return true if the listener has consumed the event (i.e., the default behavior should not occur); 
     * false otherwise (i.e., the default behavior should occur). 
     * The default behavior is for the camera to move to the marker and an info window to appear. 
     */ 
     boolean filterListByMarker(Marker marker); //the class that implements this doesn't do anything for now it just returns false 
    } 
} 

は今、あなたはそれが動作します、してみてください

答えて

2

を呼び出す必要がある場合は、そうでない場合は別のことで有効にしてください。私はメソッドを作成し、これにそれを変更し

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    if (ev.getAction() == MotionEvent.ACTION_UP) { 
     return super.dispatchTouchEvent(ev); 
    } 
    if (ev.getPointerCount() > 1) //here was the problem 
     return true; 
    return super.dispatchTouchEvent(ev); 
} 

:そのクラスには、次のメソッドをオーバーライドしていた

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 
    if (ev.getAction() == MotionEvent.ACTION_UP) { 
     return super.dispatchTouchEvent(ev); 
    } 
    if (ev.getPointerCount() > 1 && !enableMultiTouch()) 
     return true; 
    return super.dispatchTouchEvent(ev); 
} 

protected boolean enableMultiTouch(){ 
    return false; //and override it to true in my activity 
} 

が、それは誰か:)

1

コメントこのライン

googleMap.getUiSettings().setZoomGesturesEnabled(true); //not working 

、ありがとうございました。
mapFragmentは、カスタムクラスを拡張して含むアクティビティを:あなたは、特定のまたは少数のジェスチャー手段が必要な場合は、すべてがちょうど私が最終的に問題を発見し、このライン

googleMap.getUiSettings().setAllGesturesEnabled(true); 
+0

私は3行のうちのどれかを試してみました。それから私は 'setZoomControlsEnabled'を試しましたが、それは私が必要としていたものではありませんでした。そして、別のものを別々に試してみました。それから私はそれらのすべてを入れて、ここで質問しました – PhpLou

0

は、私の場合はそれが設定するのに役立ったお役に立てば幸いですMapView documentationに記載されているようにmap.getUiSettings().setAllGesturesEnabled(true);及びライフサイクルのメソッドをオーバーライドする:Fiの時

@Override 
    public void onCreate(Bundle bundle) { 
     super.onCreate(bundle); 
     mapView.onCreate(bundle); 
    } 

    @Override 
    public void onSaveInstanceState() 
    { 
     super.onSaveInstanceState(); 
     mapView.onSaveInstanceState(); 
    } 

    @Override 
    public void onPause() 
    { 
     super.onPause(); 
     mapView.onPause(); 
    } 

    @Override 
    public void onStart() 
    { 
     super.onStart(); 
     mapView.onStart(); 
    } 

    @Override 
    public void onResume() 
    { 
     super.onResume(); 
     mapView.onResume(); 
    } 

    @Override 
    public void onLowMemory() 
    { 
     super.onLowMemory(); 
     mapView.onLowMemory(); 
    } 

    @Override 
    public void onDestroy() 
    { 
     super.onDestroy(); 
     mapView.onDestroy(); 
    } 

    @Override 
    public void onStop() 
    { 
     super.onStop(); 
     mapView.onStop(); 
    } 
関連する問題