Hide

SupportMapFragment

public class SupportMapFragment extends Fragment
java.lang.Object
   ↳ android.support.v4.app.Fragment
     ↳ com.google.android.gms.maps.SupportMapFragment

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.SupportMapFragment"
    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 SupportMapFragment's onDestroyView() method is called and the useViewLifecycleInFragment(boolean) option is set. When this happens the SupportMapFragment is no longer valid until the view is recreated again later when SupportMapFragment'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.

To use this class, you must include the Android support library in your build path.

Developer Guide

For more information, read the Google Maps Android API v2 developer guide.

Public Constructor Summary

Public Method Summary

final GoogleMap
getMap()
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.
void
static SupportMapFragment
static SupportMapFragment
void
onActivityCreated(Bundle savedInstanceState)
void
onAttach(Activity activity)
void
onCreate(Bundle savedInstanceState)
View
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void
void
void
onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState)
void
void
void
void
void

Public Constructors

public SupportMapFragment ()

Creates a map fragment. This constructor is public only for use by an inflater. Use newInstance() to create a SupportMapFragment programmatically.

Public Methods

public final GoogleMap getMap ()

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.

Returns

public void getMapAsync (OnMapReadyCallback callback)

Sets a callback object which will be triggered when the 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 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.

public static SupportMapFragment newInstance ()

Creates a map fragment, using default options.

public static SupportMapFragment newInstance (GoogleMapOptions options)

Creates a map fragment with the given options.

public void onActivityCreated (Bundle savedInstanceState)

public void onAttach (Activity activity)

public void onCreate (Bundle savedInstanceState)

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

public void onDestroy ()

public void onDestroyView ()

public void onInflate (Activity activity, AttributeSet attrs, Bundle 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 outState)

public void setArguments (Bundle args)