java.lang.Object | ||
↳ | android.app.Fragment | |
↳ | com.google.android.gms.maps.MapFragment |
A Map component in an app. This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs. Being a fragment, this component can be added to an activity's layout file simply with the XML below.
<fragment class="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent"/>A
GoogleMap
must be acquired using getMapAsync(OnMapReadyCallback)
.
This class automatically initializes the maps system and the view.
A view can be removed when the MapFragment's onDestroyView()
method is called and the
useViewLifecycleInFragment(boolean)
option is set. When this happens
the MapFragment is no longer valid until the view is recreated again later when MapFragment's
onCreateView(LayoutInflater, ViewGroup, Bundle)
method is called.
Any objects obtained from the GoogleMap
is associated with the view. It's important to
not hold on to objects (e.g. Marker
) beyond the
view's life. Otherwise it will cause a memory leak as the view cannot be released.
Use this class only if you are targeting API 12 and above. Otherwise, use SupportMapFragment.
For more information, read the Google Maps Android API v2 developer guide.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a map fragment.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
Use
getMapAsync(OnMapReadyCallback) instead. The callback
method provides you with a GoogleMap instance guaranteed to be non-null and ready to
be used.
| |||||||||||
Sets a callback object which will be triggered when the
GoogleMap instance is ready
to be used.
| |||||||||||
Creates a map fragment, using default options.
| |||||||||||
Creates a map fragment with the given options.
| |||||||||||
You must call this method from the parent WearableActivity's corresponding method.
| |||||||||||
You must call this method from the parent WearableActivity's corresponding method.
| |||||||||||
Parse attributes during inflation from a view hierarchy into the arguments we handle.
| |||||||||||
Provides a
Bundle to store the state of the Fragment before it gets destroyed.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Creates a map fragment. This constructor is public only for use by an inflater. Use
newInstance()
to create a MapFragment programmatically.
This method is deprecated.
Use getMapAsync(OnMapReadyCallback)
instead. The callback
method provides you with a GoogleMap
instance guaranteed to be non-null and ready to
be used.
Gets the underlying GoogleMap
that is tied to the view wrapped by this fragment.
GoogleMap
or null
. The latter can happen when Google Play
services is not available or the view of the fragment is not yet ready. The view may
not be ready if the fragment lifecyle has not gone through
onCreateView(LayoutInflater, ViewGroup, Bundle)
yet. The return value may
be consistently null
for newer versions of Google Play services.
Sets a callback object which will be triggered when the GoogleMap
instance is ready
to be used.
Note that:
GoogleMap
object provided by the callback is non-null.
callback | The callback object that will be triggered when the map is ready to be used. |
---|
Creates a map fragment with the given options.
You must call this method from the parent WearableActivity's corresponding method.
You must call this method from the parent WearableActivity's corresponding method.
Parse attributes during inflation from a view hierarchy into the arguments we handle.
Provides a Bundle
to store the state of the Fragment before it gets destroyed. It can
later be retrieved when onCreate(Bundle)
is called again.
Note that storing custom Parcelable
objects directly in the provided Bundle will
throw a ClassNotFoundException
. This is due to the fact that this Bundle is parceled
(thus losing its attached ClassLoader) and unparceled later in a different ClassLoader.
A workaround to this issue is to store custom Parcelable
objects in another Bundle
object before putting them in the provided Bundle
.
However, note that it is safe to store Parcelable
objects from the Maps API (e.g.
MarkerOptions, LatLng, etc.) directly in the provided Bundle.