public class

MapView

extends FrameLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ com.google.android.gms.maps.MapView

Class Overview

A View which displays a map (with data obtained from the Google Maps service). When focused, it will capture keypresses and touch gestures to move the map.

Users of this class must forward all the life cycle methods from the Activity or Fragment containing this view to the corresponding ones in this class. In particular, you must forward on the following methods:

A GoogleMap must be acquired using getMapAsync(OnMapReadyCallback). The MapView automatically initializes the maps system and the view.

For a simpler method of displaying a Map use MapFragment (or SupportMapFragment) if you are looking to target earlier platforms.

Note: You are advised not to add children to this view.

Developer Guide

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

Summary

[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
MapView(Context context)
MapView(Context context, AttributeSet attrs)
MapView(Context context, AttributeSet attrs, int defStyle)
MapView(Context context, GoogleMapOptions options)
Public Methods
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 getMapAsync(OnMapReadyCallback callback)
Returns a non-null instance of the GoogleMap, ready to be used.
final void onCreate(Bundle savedInstanceState)
You must call this method from the parent Activity/Fragment's corresponding method.
final void onDestroy()
You must call this method from the parent Activity/Fragment's corresponding method.
final void onLowMemory()
You must call this method from the parent Activity/Fragment's corresponding method.
final void onPause()
You must call this method from the parent Activity/Fragment's corresponding method.
final void onResume()
You must call this method from the parent Activity/Fragment's corresponding method.
final void onSaveInstanceState(Bundle outState)
You must call this method from the parent Activity/Fragment's corresponding method.
[Expand]
Inherited Methods
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public MapView (Context context)

public MapView (Context context, AttributeSet attrs)

public MapView (Context context, AttributeSet attrs, int defStyle)

public MapView (Context context, GoogleMapOptions options)

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 this view.

Returns
  • the GoogleMap. Null if the view of the map is not yet ready. This can happen when Google Play services is not available. If Google Play services becomes available afterwards, calling this method again will initialize and return the GoogleMap.

public void getMapAsync (OnMapReadyCallback callback)

Returns a non-null instance of the GoogleMap, 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.
  • 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 final void onCreate (Bundle savedInstanceState)

You must call this method from the parent Activity/Fragment's corresponding method.

public final void onDestroy ()

You must call this method from the parent Activity/Fragment's corresponding method.

public final void onLowMemory ()

You must call this method from the parent Activity/Fragment's corresponding method.

public final void onPause ()

You must call this method from the parent Activity/Fragment's corresponding method.

public final void onResume ()

You must call this method from the parent Activity/Fragment's corresponding method.

public final void onSaveInstanceState (Bundle outState)

You must call this method from the parent Activity/Fragment's corresponding method.