# MapFragment

public class **MapFragment** extends [Fragment](https://developer.android.com/reference/android/app/Fragment.html)  
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 `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap` must be acquired using `https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)`. This class automatically initializes the maps system and the view.

A view can be removed when the MapFragment's `https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onDestroyView()`
method is called and the `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMapOptions#useViewLifecycleInFragment(boolean)` option is set. When this
happens the MapFragment is no longer valid until the view is recreated again later when the
MapFragment's `https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onCreateView(android.view.LayoutInflater,%20android.view.ViewGroup,%20android.os.Bundle)` method is called.

Any objects obtained from the `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap` are
associated with the view. It's important to not hold on to objects (e.g. `https://developers.google.com/android/reference/com/google/android/gms/maps/model/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 by adding the Android support library to your build path.

### Developer Guide

For more information, read the [Google Maps SDK for Android](https://developers.google.com/maps/documentation/android-sdk/)
developer guide.

### Inherited Constant Summary

From interface android.content.ComponentCallbacks2

|---|---|---|
| int | TRIM_MEMORY_BACKGROUND |   |
| int | TRIM_MEMORY_COMPLETE |   |
| int | TRIM_MEMORY_MODERATE |   |
| int | TRIM_MEMORY_RUNNING_CRITICAL |   |
| int | TRIM_MEMORY_RUNNING_LOW |   |
| int | TRIM_MEMORY_RUNNING_MODERATE |   |
| int | TRIM_MEMORY_UI_HIDDEN |   |

### Public Constructor Summary

|---|---|
|   | [MapFragment](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#MapFragment())() Creates a map fragment. |

### Public Method Summary

|---|---|
| void | [getMapAsync](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#getMapAsync(com.google.android.gms.maps.OnMapReadyCallback))([OnMapReadyCallback](https://developers.google.com/android/reference/com/google/android/gms/maps/OnMapReadyCallback) callback) Sets a callback object which will be triggered when the `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap` instance is ready to be used. |
| static [MapFragment](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment) | [newInstance](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#newInstance(com.google.android.gms.maps.GoogleMapOptions))([GoogleMapOptions](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMapOptions) options) Creates a map fragment with the given options. |
| static [MapFragment](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment) | [newInstance](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#newInstance())() Creates a map fragment, using default options. |
| void | [onActivityCreated](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onActivityCreated(android.os.Bundle))([Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState) |
| void | [onAttach](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onAttach(android.app.Activity))([Activity](https://developer.android.com/reference/android/app/Activity.html) activity) |
| void | [onCreate](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onCreate(android.os.Bundle))([Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState) |
| [View](https://developer.android.com/reference/android/view/View.html) | [onCreateView](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onCreateView(android.view.LayoutInflater,%20android.view.ViewGroup,%20android.os.Bundle))([LayoutInflater](https://developer.android.com/reference/android/view/LayoutInflater.html) inflater, [ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) container, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState) |
| void | [onDestroy](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onDestroy())() |
| void | [onDestroyView](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onDestroyView())() |
| final void | [onEnterAmbient](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onEnterAmbient(android.os.Bundle))([Bundle](https://developer.android.com/reference/android/os/Bundle.html) ambientDetails) You must call this method from the parent WearableActivity's corresponding method. |
| final void | [onExitAmbient](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onExitAmbient())() You must call this method from the parent WearableActivity's corresponding method. |
| void | [onInflate](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onInflate(android.app.Activity,%20android.util.AttributeSet,%20android.os.Bundle))([Activity](https://developer.android.com/reference/android/app/Activity.html) activity, [AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html) attrs, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState) Parse attributes during inflation from a view hierarchy into the arguments we handle. |
| void | [onLowMemory](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onLowMemory())() |
| void | [onPause](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onPause())() |
| void | [onResume](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onResume())() |
| void | [onSaveInstanceState](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onSaveInstanceState(android.os.Bundle))([Bundle](https://developer.android.com/reference/android/os/Bundle.html) outState) Provides a `https://developer.android.com/reference/android/os/Bundle.html` to store the state of the Fragment before it gets destroyed. |
| void | [onStart](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onStart())() |
| void | [onStop](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onStop())() |
| void | [setArguments](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#setArguments(android.os.Bundle))([Bundle](https://developer.android.com/reference/android/os/Bundle.html) args) |

### Inherited Method Summary

From class android.app.Fragment

|---|---|
| void | dump([String](https://developer.android.com/reference/java/lang/String.html) arg0, [FileDescriptor](https://developer.android.com/reference/java/io/FileDescriptor.html) arg1, [PrintWriter](https://developer.android.com/reference/java/io/PrintWriter.html) arg2, [String\[\]](https://developer.android.com/reference/java/lang/String.html) arg3) |
| final boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| final [Activity](https://developer.android.com/reference/android/app/Activity.html) | getActivity() |
| boolean | getAllowEnterTransitionOverlap() |
| boolean | getAllowReturnTransitionOverlap() |
| final [Bundle](https://developer.android.com/reference/android/os/Bundle.html) | getArguments() |
| final [FragmentManager](https://developer.android.com/reference/android/app/FragmentManager.html) | getChildFragmentManager() |
| [Context](https://developer.android.com/reference/android/content/Context.html) | getContext() |
| [Transition](https://developer.android.com/reference/android/transition/Transition.html) | getEnterTransition() |
| [Transition](https://developer.android.com/reference/android/transition/Transition.html) | getExitTransition() |
| final [FragmentManager](https://developer.android.com/reference/android/app/FragmentManager.html) | getFragmentManager() |
| final [Object](https://developer.android.com/reference/java/lang/Object.html) | getHost() |
| final int | getId() |
| final [LayoutInflater](https://developer.android.com/reference/android/view/LayoutInflater.html) | getLayoutInflater() |
| [LoaderManager](https://developer.android.com/reference/android/app/LoaderManager.html) | getLoaderManager() |
| final [Fragment](https://developer.android.com/reference/android/app/Fragment.html) | getParentFragment() |
| [Transition](https://developer.android.com/reference/android/transition/Transition.html) | getReenterTransition() |
| final [Resources](https://developer.android.com/reference/android/content/res/Resources.html) | getResources() |
| final boolean | getRetainInstance() |
| [Transition](https://developer.android.com/reference/android/transition/Transition.html) | getReturnTransition() |
| [Transition](https://developer.android.com/reference/android/transition/Transition.html) | getSharedElementEnterTransition() |
| [Transition](https://developer.android.com/reference/android/transition/Transition.html) | getSharedElementReturnTransition() |
| final [String](https://developer.android.com/reference/java/lang/String.html) | getString(int arg0, [Object...](https://developer.android.com/reference/java/lang/Object.html) arg1) |
| final [String](https://developer.android.com/reference/java/lang/String.html) | getString(int arg0) |
| final [String](https://developer.android.com/reference/java/lang/String.html) | getTag() |
| final [Fragment](https://developer.android.com/reference/android/app/Fragment.html) | getTargetFragment() |
| final int | getTargetRequestCode() |
| final [CharSequence](https://developer.android.com/reference/java/lang/CharSequence.html) | getText(int arg0) |
| boolean | getUserVisibleHint() |
| [View](https://developer.android.com/reference/android/view/View.html) | getView() |
| final int | hashCode() |
| static [Fragment](https://developer.android.com/reference/android/app/Fragment.html) | instantiate([Context](https://developer.android.com/reference/android/content/Context.html) arg0, [String](https://developer.android.com/reference/java/lang/String.html) arg1) |
| static [Fragment](https://developer.android.com/reference/android/app/Fragment.html) | instantiate([Context](https://developer.android.com/reference/android/content/Context.html) arg0, [String](https://developer.android.com/reference/java/lang/String.html) arg1, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg2) |
| final boolean | isAdded() |
| final boolean | isDetached() |
| final boolean | isHidden() |
| final boolean | isInLayout() |
| final boolean | isRemoving() |
| final boolean | isResumed() |
| final boolean | isStateSaved() |
| final boolean | isVisible() |
| void | onActivityCreated([Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg0) |
| void | onActivityResult(int arg0, int arg1, [Intent](https://developer.android.com/reference/android/content/Intent.html) arg2) |
| void | onAttach([Activity](https://developer.android.com/reference/android/app/Activity.html) arg0) |
| void | onAttach([Context](https://developer.android.com/reference/android/content/Context.html) arg0) |
| void | onAttachFragment([Fragment](https://developer.android.com/reference/android/app/Fragment.html) arg0) |
| void | onConfigurationChanged([Configuration](https://developer.android.com/reference/android/content/res/Configuration.html) arg0) |
| boolean | onContextItemSelected([MenuItem](https://developer.android.com/reference/android/view/MenuItem.html) arg0) |
| void | onCreate([Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg0) |
| [Animator](https://developer.android.com/reference/android/animation/Animator.html) | onCreateAnimator(int arg0, boolean arg1, int arg2) |
| void | onCreateContextMenu([ContextMenu](https://developer.android.com/reference/android/view/ContextMenu.html) arg0, [View](https://developer.android.com/reference/android/view/View.html) arg1, [ContextMenu.ContextMenuInfo](https://developer.android.com/reference/android/view/ContextMenu.ContextMenuInfo.html) arg2) |
| void | onCreateOptionsMenu([Menu](https://developer.android.com/reference/android/view/Menu.html) arg0, [MenuInflater](https://developer.android.com/reference/android/view/MenuInflater.html) arg1) |
| [View](https://developer.android.com/reference/android/view/View.html) | onCreateView([LayoutInflater](https://developer.android.com/reference/android/view/LayoutInflater.html) arg0, [ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) arg1, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg2) |
| void | onDestroy() |
| void | onDestroyOptionsMenu() |
| void | onDestroyView() |
| void | onDetach() |
| [LayoutInflater](https://developer.android.com/reference/android/view/LayoutInflater.html) | onGetLayoutInflater([Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg0) |
| void | onHiddenChanged(boolean arg0) |
| void | onInflate([AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html) arg0, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg1) |
| void | onInflate([Activity](https://developer.android.com/reference/android/app/Activity.html) arg0, [AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html) arg1, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg2) |
| void | onInflate([Context](https://developer.android.com/reference/android/content/Context.html) arg0, [AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html) arg1, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg2) |
| void | onLowMemory() |
| void | onMultiWindowModeChanged(boolean arg0) |
| void | onMultiWindowModeChanged(boolean arg0, [Configuration](https://developer.android.com/reference/android/content/res/Configuration.html) arg1) |
| boolean | onOptionsItemSelected([MenuItem](https://developer.android.com/reference/android/view/MenuItem.html) arg0) |
| void | onOptionsMenuClosed([Menu](https://developer.android.com/reference/android/view/Menu.html) arg0) |
| void | onPause() |
| void | onPictureInPictureModeChanged(boolean arg0, [Configuration](https://developer.android.com/reference/android/content/res/Configuration.html) arg1) |
| void | onPictureInPictureModeChanged(boolean arg0) |
| void | onPrepareOptionsMenu([Menu](https://developer.android.com/reference/android/view/Menu.html) arg0) |
| void | onRequestPermissionsResult(int arg0, [String\[\]](https://developer.android.com/reference/java/lang/String.html) arg1, int\[\] arg2) |
| void | onResume() |
| void | onSaveInstanceState([Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg0) |
| void | onStart() |
| void | onStop() |
| void | onTrimMemory(int arg0) |
| void | onViewCreated([View](https://developer.android.com/reference/android/view/View.html) arg0, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg1) |
| void | onViewStateRestored([Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg0) |
| void | postponeEnterTransition() |
| void | registerForContextMenu([View](https://developer.android.com/reference/android/view/View.html) arg0) |
| final void | requestPermissions([String\[\]](https://developer.android.com/reference/java/lang/String.html) arg0, int arg1) |
| void | setAllowEnterTransitionOverlap(boolean arg0) |
| void | setAllowReturnTransitionOverlap(boolean arg0) |
| void | setArguments([Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg0) |
| void | setEnterSharedElementCallback([SharedElementCallback](https://developer.android.com/reference/android/app/SharedElementCallback.html) arg0) |
| void | setEnterTransition([Transition](https://developer.android.com/reference/android/transition/Transition.html) arg0) |
| void | setExitSharedElementCallback([SharedElementCallback](https://developer.android.com/reference/android/app/SharedElementCallback.html) arg0) |
| void | setExitTransition([Transition](https://developer.android.com/reference/android/transition/Transition.html) arg0) |
| void | setHasOptionsMenu(boolean arg0) |
| void | setInitialSavedState([Fragment.SavedState](https://developer.android.com/reference/android/app/Fragment.SavedState.html) arg0) |
| void | setMenuVisibility(boolean arg0) |
| void | setReenterTransition([Transition](https://developer.android.com/reference/android/transition/Transition.html) arg0) |
| void | setRetainInstance(boolean arg0) |
| void | setReturnTransition([Transition](https://developer.android.com/reference/android/transition/Transition.html) arg0) |
| void | setSharedElementEnterTransition([Transition](https://developer.android.com/reference/android/transition/Transition.html) arg0) |
| void | setSharedElementReturnTransition([Transition](https://developer.android.com/reference/android/transition/Transition.html) arg0) |
| void | setTargetFragment([Fragment](https://developer.android.com/reference/android/app/Fragment.html) arg0, int arg1) |
| void | setUserVisibleHint(boolean arg0) |
| boolean | shouldShowRequestPermissionRationale([String](https://developer.android.com/reference/java/lang/String.html) arg0) |
| void | startActivity([Intent](https://developer.android.com/reference/android/content/Intent.html) arg0) |
| void | startActivity([Intent](https://developer.android.com/reference/android/content/Intent.html) arg0, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg1) |
| void | startActivityForResult([Intent](https://developer.android.com/reference/android/content/Intent.html) arg0, int arg1) |
| void | startActivityForResult([Intent](https://developer.android.com/reference/android/content/Intent.html) arg0, int arg1, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg2) |
| void | startIntentSenderForResult([IntentSender](https://developer.android.com/reference/android/content/IntentSender.html) arg0, int arg1, [Intent](https://developer.android.com/reference/android/content/Intent.html) arg2, int arg3, int arg4, int arg5, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) arg6) |
| void | startPostponedEnterTransition() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| void | unregisterForContextMenu([View](https://developer.android.com/reference/android/view/View.html) arg0) |

From class java.lang.Object

|---|---|
| [Object](https://developer.android.com/reference/java/lang/Object.html) | clone() |
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| void | finalize() |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface android.content.ComponentCallbacks2

|---|---|
| abstract void | onTrimMemory(int arg0) |

From interface android.view.View.OnCreateContextMenuListener

|---|---|
| abstract void | onCreateContextMenu([ContextMenu](https://developer.android.com/reference/android/view/ContextMenu.html) arg0, [View](https://developer.android.com/reference/android/view/View.html) arg1, [ContextMenu.ContextMenuInfo](https://developer.android.com/reference/android/view/ContextMenu.ContextMenuInfo.html) arg2) |

From interface android.content.ComponentCallbacks

|---|---|
| abstract void | onConfigurationChanged([Configuration](https://developer.android.com/reference/android/content/res/Configuration.html) arg0) |
| abstract void | onLowMemory() |

## Public Constructors

#### public **MapFragment** ()

Creates a map fragment. This constructor is public only for use by an inflater. Use
`https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#newInstance()`
to create a MapFragment programmatically.

## Public Methods

#### public void **getMapAsync** ([OnMapReadyCallback](https://developers.google.com/android/reference/com/google/android/gms/maps/OnMapReadyCallback) callback)

Sets a callback object which will be triggered when the `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap`
instance is ready to be used.

Note that:

- This method must be called from the main thread.
- The callback will be executed in the main thread.
- In the case where Google Play services is not installed on the user's device, the callback will not be triggered until the user installs it.
- In the rare case where the GoogleMap is destroyed immediately after creation, the callback is not triggered.
- The `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap` object provided by the callback is non-null.

##### Parameters

| callback | The callback object that will be triggered when the map is ready to be used. Must not be `null`. |
|---|---|

#### public static [MapFragment](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment)
**newInstance** ([GoogleMapOptions](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMapOptions) options)

Creates a map fragment with the given options.

##### Parameters

| options | configuration GoogleMapOptions for a `https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap`, or `null` to use the default options. |
|---|---|

#### public static [MapFragment](https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment)
**newInstance** ()

Creates a map fragment, using default options.

#### public void **onActivityCreated** ([Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState)

#### public void **onAttach** ([Activity](https://developer.android.com/reference/android/app/Activity.html) activity)

#### public void **onCreate** ([Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState)

#### public [View](https://developer.android.com/reference/android/view/View.html) **onCreateView** ([LayoutInflater](https://developer.android.com/reference/android/view/LayoutInflater.html) inflater, [ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) container, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState)

#### public void **onDestroy** ()

#### public void **onDestroyView** ()

#### public final void **onEnterAmbient** ([Bundle](https://developer.android.com/reference/android/os/Bundle.html) ambientDetails)

You must call this method from the parent WearableActivity's corresponding
method.

#### public final void **onExitAmbient** ()

You must call this method from the parent WearableActivity's corresponding
method.

#### public void **onInflate** ([Activity](https://developer.android.com/reference/android/app/Activity.html) activity, [AttributeSet](https://developer.android.com/reference/android/util/AttributeSet.html) attrs, [Bundle](https://developer.android.com/reference/android/os/Bundle.html) savedInstanceState)

Parse attributes during inflation from a view hierarchy into the arguments we
handle.

#### public void **onLowMemory** ()

#### public void **onPause** ()

#### public void **onResume** ()

#### public void **onSaveInstanceState** ([Bundle](https://developer.android.com/reference/android/os/Bundle.html) outState)

Provides a `https://developer.android.com/reference/android/os/Bundle.html` to store
the state of the Fragment before it gets destroyed. It can later be retrieved when
`https://developers.google.com/android/reference/com/google/android/gms/maps/MapFragment#onCreate(android.os.Bundle)` is called again.

#### public void **onStart** ()

#### public void **onStop** ()

#### public void **setArguments** ([Bundle](https://developer.android.com/reference/android/os/Bundle.html) args)