void LoadMap(){ // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); }
private void toggleMapAndList() { state = state == State.MAP ? State.LIST : State.MAP; if (state == State.LIST) { if (mapFragment != null) { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.hide(mapFragment).commit(); } recyclerView.setVisibility(View.VISIBLE); currentPlaceCardView.setVisibility(View.VISIBLE); } if (state == State.MAP) { if (mapFragment == null) { mapFragment = SupportMapFragment.newInstance(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); transaction.replace(R.id.place_search_map_placeholder, mapFragment); transaction.commit(); mapFragment.getMapAsync(this); } else { FragmentTransaction ft = getChildFragmentManager().beginTransaction(); ft.show(mapFragment).commit(); } recyclerView.setVisibility(View.INVISIBLE); currentPlaceCardView.setVisibility(View.INVISIBLE); } displayPlaces(placesToDisplay); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) { View view = super.onCreateView(inflater, viewGroup, bundle); setUpMapIfNeeded(); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (readyToGo()) { setContentView(R.layout.activity_main); SupportMapFragment mapFrag= (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); if (savedInstanceState == null) { needsInit=true; } mapFrag.setRetainInstance(true); mapFrag.getMapAsync(this); } }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); SupportMapFragment mapFragment = getMapFragment(); if (BuildConfig.DEBUG) { Log.d(YourApplication.LOG_TAG, "simpleMapFragment.onViewCreated - mapFragment = " + mapFragment); } if (mapFragment == null) { mapFragment = new SupportMapFragment(); mapFragment.setRetainInstance(true); getChildFragmentManager().beginTransaction().replace(R.id.simplemap, mapFragment, null).commit(); } mapFragment.getMapAsync(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); window = getWindow(); initColors(); initAnimationRelatedFields(); content = findViewById(R.id.content); toolbar = findViewById(R.id.toolbar); TextView title = (TextView) findViewById(R.id.toolbar_title); title.setText(R.string.app_name); iconSwitch = (IconSwitch) findViewById(R.id.icon_switch); iconSwitch.setCheckedChangeListener(this); updateColors(false); FragmentManager fm = getSupportFragmentManager(); SupportMapFragment fragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container); if (fragment == null) { fragment = new SupportMapFragment(); fm.beginTransaction().replace(R.id.map_container, fragment).commit(); } fragment.getMapAsync(this); findViewById(R.id.credit_polyak).setOnClickListener(this); findViewById(R.id.credit_yarolegovich).setOnClickListener(this); findViewById(R.id.credit_prokhoda).setOnClickListener(this); }
mapFragment = SupportMapFragment.newInstance(); getSupportFragmentManager().beginTransaction().replace(R.id.map, mapFragment).commit(); map = mapFragment.getMap();
/** * Retrieves a map if the map fragment parameter is null. * <p> * If there is an error tries to solve it checking if it was because of * "Google Play Services" sending the corresponding intent. * * @param mMap map fragment to check if the map is already initialized * @return initialized map fragment */ private GoogleMap retrieveMap(GoogleMap mMap) { // Do a null check to confirm that we have not already instantiated the map. mMapFailed = false; if (mMap == null) { mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)) .getMap(); // Check if we were successful in obtaining the map. if (mMap == null) { int status = GooglePlayServicesUtil .isGooglePlayServicesAvailable(mApplicationContext); if (status != ConnectionResult.SUCCESS) { enableUIElements(false); Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, getActivity(), OTPApp.CHECK_GOOGLE_PLAY_REQUEST_CODE); dialog.show(); mMapFailed = true; } } } return mMap; }
@Override public Fragment getItem(int position) { switch (position) { case 0: case 1: return new TextFragment(); case 2: return SupportMapFragment.newInstance(); default: return null; } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.basic_demo); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); if (savedInstanceState == null) { // First incarnation of this activity. mapFragment.setRetainInstance(true); } mapFragment.getMapAsync(this); }
.findFragmentById(R.id.map)).getMap(); mMap.setOnMarkerDragListener(this);
private void init() { Log.d("NGVL", "init::BEGIN"); SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(TAG); if (fragment == null) { fragment = SupportMapFragment.newInstance(); getSupportFragmentManager() .beginTransaction() .replace(R.id.map, fragment, TAG) .commit(); } mGoogleApiClient.connect(); Log.d("NGVL", "init::END"); } }
private void setUpMap() { ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // It isn't possible to set a fragment's id programmatically so we set a tag instead and // search for it using that. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG); // We only create a fragment if it doesn't already exist. if (mapFragment == null) { // To programmatically add the map, we first create a SupportMapFragment. mapFragment = SupportMapFragment.newInstance(); // Then we add it using a FragmentTransaction. FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(android.R.id.content, mapFragment, MAP_FRAGMENT_TAG); fragmentTransaction.commit(); } mapFragment.getMapAsync(this); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); init(); return v; }
LatLngBounds routeBounds = boundsCreator.build(); if (((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)) .getMap() != null){ showRouteOnMapAnimateCamera(routeBounds, firstTransitMarker, animateCamera);
private void onCreateForRealz(boolean canGetLocation) { if (canGetLocation) { if (readyToGo()) { setContentView(R.layout.activity_main); SupportMapFragment mapFrag= (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); mapFrag.getMapAsync(this); } } else if (!isInPermission) { isInPermission=true; ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMS); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready // to be used. SupportMapFragment mapFragment = SupportMapFragment.newInstance(); getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, mapFragment).commit(); mapFragment.getMapAsync(this); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { mOriginalContentView = super.onCreateView(inflater, parent, savedInstanceState); mTouchView = new TouchableWrapper(getActivity()); mTouchView.addView(mOriginalContentView); return mTouchView; }
@Override public void onStart() { super.onStart(); mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); if (mMapFailed) { mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)) .getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { enableUIElements(true); initializeMapInterface(mMap); runAutoDetectServerNoLocation(true); } } connectLocationClient(); }