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)
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)
| 归档时间: |
|
| 查看次数: |
4944 次 |
| 最近记录: |