Integrating Huawei Map Kit in HarmonyOS


In this article, we will learn about Huawei Map Kit in HarmonyOS. Map Kit is an SDK for map development. It covers map data of more than 200 countries and regions and supports over 70 languages. With this SDK, you can easily integrate map-based functions into your HarmonyOS application.

Development Overview

You need to install DevEcho Studio IDE and I assume that you have prior knowledge about HarmonyOS and Java.

Hardware Requirements

  • A computer (desktop or laptop) running windows 10.
  • A HarmonyOS Smart Watch (with the USB cable), which is used for debugging.

Software Requirements

  • Java JDK installation package.
  • DevEcho Studio installed.


Step 1: Create a HarmonyOS Application.

Let’s start coding.

public class MapAbilitySlice extends AbilitySlice {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "TAG");
    private MapView mMapView;

    public void onStart(Intent intent) {

        // Declaring and Initializing the HuaweiMapOptions Object
        HuaweiMapOptions huaweiMapOptions = new HuaweiMapOptions();
        // Initialize Camera Properties
        CameraPosition cameraPosition =
            new CameraPosition(new LatLng(12.972442, 77.580643), 10, 0, 0);
            // Set Camera Properties
            // Enables or disables the zoom function. By default, the zoom function is enabled.
            // Sets whether the compass is available. The compass is available by default.
            // Specifies whether the zoom gesture is available. By default, the zoom gesture is available.
            // Specifies whether to enable the scrolling gesture. By default, the scrolling gesture is enabled.
            // Specifies whether the rotation gesture is available. By default, the rotation gesture is available.
            // Specifies whether the tilt gesture is available. By default, the tilt gesture is available.
            // Sets whether the map is in lite mode. The default value is No.
            // Set Preference Minimum Zoom Level
            // Set Preference Maximum Zoom Level
        // Initialize the MapView object.
        mMapView = new MapView(this, huaweiMapOptions);
        // Create the MapView object.
        // Obtains the HuaweiMap object.
        mMapView.getMapAsync(new OnMapReadyCallback() {

            public void onMapReady(HuaweiMap huaweiMap) {
                HuaweiMap mHuaweiMap = huaweiMap;
                mHuaweiMap.setOnMapClickListener(new OnMapClickListener() {

                    public void onMapClick(LatLng latLng) {
                        new ToastDialog(CommonContext.getContext()).setText("onMapClick ").show();

                // Initialize the Circle object.
                Circle mCircle = new Circle(this);
                if (null == mHuaweiMap) {
                if (null != mCircle) {
                    mCircle = null;
                mCircle = mHuaweiMap.addCircle(new CircleOptions()
                    .center(new LatLng(12.972442, 77.580643))

                new ToastDialog(CommonContext.getContext()).setText("color green: " + Color.GREEN.getValue()).show();
                int strokeColor = Color.RED.getValue();
                float strokeWidth = 15.0 f;

                // Set the edge color of a circle

                // Sets the edge width of a circle
        // Create a layout.
        ComponentContainer.LayoutConfig config = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT);
        PositionLayout myLayout = new PositionLayout(this);
        ShapeElement element = new ShapeElement();
        element.setRgbColor(new RgbColor(255, 255, 255));


Tips and Tricks

  • Add required dependencies without fail.
  • Add required images in resources > base > media.
  • Add custom strings in resources > base > element > string.json.
  • Define supporting devices in config.json file.
  • Do not log sensitive data.
  • Enable the required service in AppGallery Connect.
  • Use respective Log methods to print logs.


Leave a Comment