Integrating Huawei Map kit in HarmonyOs Wearable Device Application
Tags: harmonyos, map, huaweidevelopers, appgallery
Published: 2022-02-04 09:28:17


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i5gh5ub8oqz5i80dkgnr.jpg)
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.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mt3mpjc9ogsnam4aeas7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydr9f931btse3kvbhnzd.png)

Development Overview

You need to install DevEcho Studio IDE and I assume that you have prior knowledge about the Harmony Os 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.

 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dak3cyj8jsw0ixexc5wk.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ut7e6ddluubhvwti1tpd.png)
  

Step 1: Create a project in [AppGallery](https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0)

Step 2: [Configure App ](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/harmonyos-config-agc-0000001153340474)in AppGallery

Step 3: Follow the SDK [integration steps](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/harmonyos-sdk-integrating-sdk-0000001101419182)


Let's start coding

MapAbilitySlice.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.0f;

// 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
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0fk7fdqc5vgt2wnmliz.png)
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 the sensitive data.
Enable required service in AppGallery Connect.
Use respective Log methods to print logs.
Conclusion

In this article, we have learnt, integration of Huawei Map in HarmonyOs wearable device using Huawei Map Kit. Sample application shows how to implement Map kit in HarmonyOs Wearables device. Hope this articles helps you to understand and integration of map kit, you can use this feature in your HarmonyOs application to display map in wearable devices.

Thank you so much for reading this article and I hope this article helps you to understand Huawei Map Kit in HarmonyOS. Please provide your comments in the comment section and like.

References

[Map Kit](https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/harmonyos-sdk-introduction-0000001147819099)
[Checkout in forum ](https://forums.developer.huawei.com/forumPortal/en/topic/0201793437026930167?ha_source=hms1)