/** * 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; }
.findFragmentById(R.id.map)).getMap(); mMap.setOnMarkerDragListener(this);
LatLngBounds routeBounds = boundsCreator.build(); if (((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)) .getMap() != null){ showRouteOnMapAnimateCamera(routeBounds, firstTransitMarker, animateCamera);
@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(); }
getSupportFragmentManager().beginTransaction().replace(R.id.map, mapFragment).commit(); map = mapFragment.getMap();
@SuppressWarnings("unchecked") private void setUpMapIfNeeded() { if (map != null) { return; } Fragment fragment = getChildFragmentManager().findFragmentById(R.id.support_map_fragment); if (fragment == null) { throw new IllegalStateException("Map fragment not found."); } map = ((SupportMapFragment) fragment).getMap(); if (map == null) { throw new IllegalStateException("Map not found in fragment."); } getMap().moveCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(getDefaultLatitude(), getDefaultLongitude()), getDefaultZoom())); RealmClusterManager<M> realmClusterManager = new RealmClusterManager<>(getActivity(), getMap()); RealmResults<M> realmResults = realm.where(clazz).findAll(); realmClusterManager.updateRealmResults( realmResults, getTitleColumnName(), getLatitudeColumnName(), getLongitudeColumnName()); realmClusterManager.setRenderer( new RealmClusterRenderer(getActivity(), getMap(), realmClusterManager)); getMap().setOnCameraChangeListener(realmClusterManager); getMap().setOnMarkerClickListener(realmClusterManager); getMap().setOnInfoWindowClickListener(realmClusterManager); }