目录

MapView

Class Info

public class MapView

Class inherited from FrameLayout and representing a map view. (The view data is obtained from Map Kit.)

If you load a map using MapView, you must apply lifecycle methods of the Activity or Fragment containing the map view to corresponding methods in MapView. The methods include the following:

The HuaweiMap object must be obtained using getMapAsync(OnMapReadyCallback callback). This class will automatically initialize the map system and view.

NOTE:

You are advised not to add subviews to MapView.

Public Constructor Summary

If the input parameter is not of the Activity type, no update wizard will be displayed to a user when HMS Core (APK) needs to be updated. Instead, the error information "Hms is not available26" is displayed. In such case, HMS Core (APK) needs to be manually updated. To show the update wizard, you are advised to pass a parameter of the Activity type instead of the Context type to create a MapView instance.

Constructor Name

MapView(Context context)

Creates a MapView object using the context.

MapView(Context context, AttributeSet attrs)

Creates a MapView object based on specified parameters.

MapView(Context context, AttributeSet attrs, int defStyle)

Creates a MapView object based on specified parameters.

MapView(Context context, HuaweiMapOptions options)

Creates a MapView object based on specified parameters.

Public Method Summary

Qualifier and Type

Method Name and Description

void

getMapAsync(OnMapReadyCallback callback)

Obtains a HuaweiMap object when the object is ready.

void

onCreate(Bundle savedInstanceState)

Called when a map is created.

void

onDestroy()

Called when a map is destroyed.

void

onLowMemory()

Called when the memory is insufficient.

void

onPause()

Called when an activity is paused.

void

onResume()

Called when an activity is ready.

void

onSaveInstanceState(Bundle outState)

Called to save the current map status upon unexpected exit.

void

onStart()

Called when an activity is created successfully. Then the map is visible.

void

onStop()

Called when an activity exits. Then the map is invisible.

Public Constructors

[h2]MapView(Context context)

Constructor

public MapView(Context context)

Creates a MapView object using the context.

Parameters

Name

Description

context

Context.

[h2]MapView(Context context, AttributeSet attrs)

Constructor

public MapView(Context context, AttributeSet attrs)

Creates a MapView object based on specified parameters.

Parameters

Name

Description

context

Context.

attrs

Collection of MapView attributes in the XML file.

[h2]MapView(Context context, AttributeSet attrs, int defStyle)

Constructor

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

Creates a MapView object based on specified parameters.

Parameters

Name

Description

context

Context.

attrs

Collection of MapView attributes in the XML file.

defStyle

Attributes of the current theme, including reference to the style resource. The resource provides default values for the map view. The value 0 indicates that default values are not used.

[h2]MapView(Context context, HuaweiMapOptions options)

Constructor

public MapView(Context context, HuaweiMapOptions options)

Creates a MapView object based on specified parameters.

Parameters

Name

Description

context

Context.

options

HuaweiMapOptions instance that contains configurations about the map.

Public Methods

[h2]getMapAsync

Method

public void getMapAsync(OnMapReadyCallback callback)

Obtains a HuaweiMap object when the object is ready.

NOTE:
  • This method must be called in the main thread.
  • The callback will be executed in the main thread.
  • The HuaweiMap object provided by the callback cannot be empty.

Parameters

Name

Description

callback

Callback to be executed when a HuaweiMap object is ready for use.

[h2]onCreate

Method

public void onCreate(Bundle savedInstanceState)

Called when a map is created. If this method needs to be reloaded, call it from the parent class.

Parameters

Name

Description

savedInstanceState

Map status to be saved.

[h2]onDestroy

Method

public void onDestroy()

Called when a map is destroyed. If this method needs to be reloaded, call it from the parent class.

[h2]onLowMemory

Method

public void onLowMemory()

Called when the memory is insufficient. If this method needs to be reloaded, call it from the parent class.

[h2]onPause

Method

public void onPause()

Called when an activity is paused. If this method needs to be reloaded, call it from the parent class.

[h2]onResume

Method

public void onResume()

Called when an activity is ready. If this method needs to be reloaded, call it from the parent class.

[h2]onSaveInstanceState

Method

public void onSaveInstanceState(Bundle outState)

Called to save map data upon unexpected app exit.

If this method needs to be reloaded, call it from the parent class.

Parameters

Name

Description

outState

Map data to be saved.

[h2]onStart

Method

public void onStart()

Called when an activity is created successfully. Then the map is visible. If this method needs to be reloaded, call it from the parent class.

[h2]onStop

Method

public void onStop()

Called when an activity exits. Then the map is invisible. If this method needs to be reloaded, call it from the parent class.