SupportMapFragmentの追加はプログラムで機能します。フラグメントの実装では:
...
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
...
@Override
public void onStart() {
super.onStart();
// add fragment
mMapFragment = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.game_map_container, mMapFragment);
fragmentTransaction.commit();
// add a marker
map = mMapFragment.getMap();
if (map != null) {
// The Map is verified. It is now safe to manipulate the map.
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.addMarker(new MarkerOptions().position(target));
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(target, 10));
} else {
Log.e(TAG, "map is not available");
}
}
実際、このアイデアは、MapsAPIv2を使用してプログラムでMapFragmentを初期化することから盗まれます。