View map in mode satellite and terrain

元气小坏坏 提交于 2019-12-21 20:33:51

问题


I tried to create a menu on the screen, where the menu will display the map in satellite mode and terrain.

My code:

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));
}

回答1:


You need to refresh the MapView after you make the changes to its settings by calling invalidate(). So your code will look something like

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));
}


来源:https://stackoverflow.com/questions/17386364/view-map-in-mode-satellite-and-terrain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!