我试图在屏幕上创建一个菜单,菜单将以卫星模式和地形显示地图。
我的代码:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_MyLocation:
//startActivity(new Intent(this, MyLocation.class));
return(true);
case MENU_LocationCar:
startActivity(new Intent(this, Gps.class));
return(true);
case MENU_Satellite:
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
return(true);
case MENU_Terrain:
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
return(true);
}
return(super.onOptionsItemSelected(item));
}
最佳答案
在通过调用MapView
对其设置进行更改后,需要刷新invalidate()
。
所以你的代码看起来像
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_MyLocation:
//startActivity(new Intent(this, MyLocation.class));
return(true);
case MENU_LocationCar:
startActivity(new Intent(this, Gps.class));
return(true);
case MENU_Satellite:
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.invalidate();
return(true);
case MENU_Terrain:
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
map.invalidate();
return(true);
}
return(super.onOptionsItemSelected(item));
}