DZone
Integration Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Integration Zone > Integrating Huawei Map Kit in HarmonyOS

Integrating Huawei Map Kit in HarmonyOS

Learn how to integrate Huawei's Map Kit into HarmonyOS to help bring maps to your wearable devices.

Siddu Shikkerimath user avatar by
Siddu Shikkerimath
·
Feb. 13, 22 · Integration Zone · Tutorial
Like (2)
Save
Tweet
6.54K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

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.

Steps

Step 1: Create a HarmonyOS Application.

  • Step 1: Create a project in AppGallery
  • Step 2: Configure App in AppGallery
  • Step 3: Follow the SDK integration steps

Let's start coding.

MapAbilitySlice.java

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

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        CommonContext.setContext(this);

        // 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);
        huaweiMapOptions
            // Set Camera Properties
            .camera(cameraPosition)
            // Enables or disables the zoom function. By default, the zoom function is enabled.
            .zoomControlsEnabled(false)
            // Sets whether the compass is available. The compass is available by default.
            .compassEnabled(true)
            // Specifies whether the zoom gesture is available. By default, the zoom gesture is available.
            .zoomGesturesEnabled(true)
            // Specifies whether to enable the scrolling gesture. By default, the scrolling gesture is enabled.
            .scrollGesturesEnabled(true)
            // Specifies whether the rotation gesture is available. By default, the rotation gesture is available.
            .rotateGesturesEnabled(false)
            // Specifies whether the tilt gesture is available. By default, the tilt gesture is available.
            .tiltGesturesEnabled(true)
            // Sets whether the map is in lite mode. The default value is No.
            .liteMode(false)
            // Set Preference Minimum Zoom Level
            .minZoomPreference(3)
            // Set Preference Maximum Zoom Level
            .maxZoomPreference(13);
        // Initialize the MapView object.
        mMapView = new MapView(this, huaweiMapOptions);
        // Create the MapView object.
        mMapView.onCreate();
        // Obtains the HuaweiMap object.
        mMapView.getMapAsync(new OnMapReadyCallback() {

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

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

                // Initialize the Circle object.
                Circle mCircle = new Circle(this);
                if (null == mHuaweiMap) {
                    return;
                }
                if (null != mCircle) {
                    mCircle.remove();
                    mCircle = null;
                }
                mCircle = mHuaweiMap.addCircle(new CircleOptions()
                    .center(new LatLng(12.972442, 77.580643))
                    .radius(500)
                    .fillColor(Color.GREEN.getValue()));

                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
                mCircle.setStrokeColor(strokeColor);

                // Sets the edge width of a circle
                mCircle.setStrokeWidth(strokeWidth);
            }
        });
        // Create a layout.
        ComponentContainer.LayoutConfig config = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT);
        PositionLayout myLayout = new PositionLayout(this);
        myLayout.setLayoutConfig(config);
        ShapeElement element = new ShapeElement();
        element.setShape(ShapeElement.RECTANGLE);
        element.setRgbColor(new RgbColor(255, 255, 255));
        myLayout.addComponent(mMapView);
        super.setUIContent(myLayout);
    }
}

Result 

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.
Java (programming language) Software requirements application Software development kit Data (computing) Requirement Integration app Java Development Kit Strings

Published at DZone with permission of Siddu Shikkerimath. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Implementing Microservices Architectures
  • Artificial Intelligence (AI) And Its Assistance in Medical Diagnosis
  • Major PostgreSQL Features You Should Know About
  • The Power of Enum: Make Your Code More Readable and Efficient [Video]

Comments

Integration Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo