谷歌地图没有手势工作

时间:2017-12-28 16:27:19

标签: java android google-maps

我创建了一个如下所示的Map Fragment:

  public class MapsFragment extends Fragment implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.activity_maps, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        SupportMapFragment supportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
        supportMapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(final GoogleMap googleMap) {
        mMap = googleMap;
        googleMap.getUiSettings().setZoomGesturesEnabled(true);
        mMap.getUiSettings().setZoomGesturesEnabled(true);
        final LatLng latlg = new LatLng(40.730610,  -73.935242);
        mMap.addMarker(new MarkerOptions().position(latlg));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latlg));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(12.0f));


    }
}

activity_maps.xml:

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="tagonsoft.com.kidgonet.gui.fragments.MapsFragment" />

我从一项活动中调用以下片段:

 public class MyActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
           Fragment mFragment = null;
            mFragment = new MapsFragment();
            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.fragment_overview, mFragment).commit();
           }          
    }  

以下xml是MyActivity的内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >
 <FrameLayout
        android:id="@+id/fragment_overview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
     />
</RelativeLayout>

我确实看到了地图视图,它运行正常。唯一的问题是我无法拖动地图以查看其他地方或缩放地图。

我遵循谷歌的地图活动模型。当我启动MapsActivity(由谷歌提供)时,一切都很好。我唯一改变的是将MapsActivity制作成片段。我尝试使用googleMap.getUiSettings().setAllGesturesEnabled(true);,但它没有用。

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题。上面的代码工作正常。这是我的错误,我也实现了导航抽屉,导航抽屉在地图视图上方,这就是我无法访问地图拖动或任何手势的原因。