当您点击抽屉上的项目时,我有导航抽屉,它应该在活动中更改谷歌地图上的地图类型。 但是当我点击抽屉上的项目,地图类型没有改变活动,在我点击抽屉之前..地图加载好并显示标记..但是当我点击它显示空白地图和标记
这是我的MainActivity
public class DirectionRoute extends ActionBarActivity implements AdapterView.OnItemClickListener, GoogleMap.OnMarkerClickListener {
private DrawerLayout drawerLayout;
private ListView listViewLeft, listViewRight;
private ActionBarDrawerToggle drawerListener;
GoogleMap googleMap;
MyNDAdapterLeft myNDAdapterLeft;
MyNDAdapterRight myNDAdapterRight;
MediaPlayer mpMarkerClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.direction_route);
mpMarkerClick = MediaPlayer.create(this, R.raw.button31);
listViewLeft = (ListView) findViewById(R.id.drawerListLeft);
myNDAdapterLeft = new MyNDAdapterLeft(this);
listViewLeft.setAdapter(myNDAdapterLeft);
listViewLeft.setOnItemClickListener(this);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
drawerListener = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
listViewRight = (ListView) findViewById(R.id.drawerListRight);
myNDAdapterRight = new MyNDAdapterRight(this);
//Getting Map From Google
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.setTrafficEnabled(true);
listViewRight.setAdapter(myNDAdapterRight);
listViewRight.setOnItemClickListener(this);
drawerLayout.setDrawerListener(drawerListener);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItemLeft(position);
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
switch (position) {
case 0:
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mpMarkerClick.start();
case 1:
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
mpMarkerClick.start();
case 2:
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mpMarkerClick.start();
case 3:
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mpMarkerClick.start();
case 4:
googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);
mpMarkerClick.start();
}
drawerLayout.closeDrawer(listViewLeft);
}
我很喜欢尝试像这样的onItemClick方法
switch (position) {
case 0:
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
*googleMap = supportMapFragment.getMap();*
mpMarkerClick.start();
但没有任何反应,地图仍然空白..
我已经看到如何在this中更改Android Google地图中的地图类型,对我的问题毫无帮助,
如何使用导航抽屉更改地图类型?