在模式卫星和地形中查看地图

Mad*_*Boy 5 android google-maps google-maps-android-api-2

我尝试在屏幕上创建一个菜单,该菜单将在卫星模式和地形中显示地图。

我的代码:

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));
}
Run Code Online (Sandbox Code Playgroud)

Ant*_*met 3

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));
}
Run Code Online (Sandbox Code Playgroud)

  • 我得到“方法无效对于 GoogleMap 类型未定义”,所以这对我不起作用。 (2认同)