Map fragment will be the default fragment and on a click a new fragment should be loaded and a value has to be entered in the fragment and this value has to be passed to the map fragment
To use MapFragment in Fragment Follow this link
using the Support Library to work (SupportMapFragment instead of MapFragment), so that the MapFragment can even work on below Android 3.0. You can replace the SupportMapFragment with the MapFragment if you are working on Android 3.0 or above.
Related
I'm creating programmatically a Huawei map, but despite MapFragment() is a child of Fragment class, the transaction add doesn't recognize it as a Fragment. Here's my code:
val transaction: FragmentTransaction = activity.supportFragmentManager.beginTransaction()
val mapFragment = MapFragment()
transaction.add(this.frame.id, mapFragment) ---> here is the problem
transaction.commit()
Someone knows the reason?
There are 2 different classes for showing map in fragment:
MapFragment
SupportMapFragment
You must use correct one your activity.
If Activity is just Activity and you use just FragmentManager - use MapFragment
If activity is AppCompatActivity and you use SupportFragmentManager - use SupportMapFragment
i want to put google maps in a tab using viewPager ,thus viewPager uses fragments, i found multiple solutions that use the deprecated getMap, so android studio wouldn't even compile it, is there any up to date solution to get the map with viewPager ?
In onCreateView in the mapsActivity.java that extends android.support.v4.app.Fragment and implements OnMapReadyCallback :
View rootView =inflater.inflate(R.layout.activity_maps, container, false);
Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
I have a viewpager where each "page" is a fragment. Each of the "page fragments" have a map fragment (google maps sdk for android) inside, added programatically using getSupportFragmentManager (If I use getFragmentManager it doesn't work either). Each added map is a new instance of SupportMapFragment (MapFragment doesn't work either).
On the first fragment, the one that is first added to the viewpager, the map works. At the other fragments, the non-interactive map just show itself as a grey square.
I'm using the 'com.google.android.gms:play-services-maps:7.5.0' dependency.
All the added maps are using the lite version. I'm doing this with:
GoogleMapOptions options = new GoogleMapOptions();
options.liteMode(true);
options.mapToolbarEnabled(false);
SupportMapFragment mapFragment = SupportMapFragment.newInstance(options);
I've read on some blogspots and here on Stackoverflow that maybe an app can only have one instance of google maps per process. Have anybody faced the same problem? Is my guess correct?
Thanks.
If you want to put a fragment into an other fragment, use getChildFragmentManager() instead of getSupportFragmentManager()
getChildFragmentManager
Return a private FragmentManager for placing and managing Fragments
inside of this Fragment.
I have a fragment activity as seen in my last question:
App crashing when using fragments
It crushes because of a GoogleMap inside one of my fragments (MainActivity).
right now thats the code:
private GoogleMap map;
map = ((MapFragment) getActivity().getFragmentManager() .findFragmentById(R.id.map)).getMap();
I cant change GoogleMap. it causes other problems in my code as im using it.
What should I do?
Thanks for your assistance!
Ive tried to relocate that piece of code to onCreateView. Doesn't work either.
In my android project, I would like to create a Google Map using java code rather than useing xml, how should I do?
You can add a Map using MapFragment to an Activity in code. To do this, create a new MapFragment instance, and then call FragmentTransaction.add() to add the Fragment to the current Activity.
mMapFragment = MapFragment.newInstance();
FragmentTransaction fragmentTransaction =getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.my_container, mMapFragment);
fragmentTransaction.commit();
For more details check out the GoogleMaps, you will have more idea of implementing the maps.