Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View map in mode satellite and terrain

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));
}
like image 301
MadBoy Avatar asked Oct 21 '22 06:10

MadBoy


1 Answers

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));
}
like image 137
Antrromet Avatar answered Nov 15 '22 05:11

Antrromet