👨🏼‍💻HarmonyOS Map Usage

Ece Aydın
Huawei Developers
Published in
3 min readJun 30, 2022

--

Harmony OS

Introduction

Hello everyone,

Today I am going to explain to you what is HarmonyOS Map Kit and its usage in a project.

With Huawei Map Kit you can use map display, map interaction and map drawing features on your HarmonyOS projects for Huawei smartwatches. Map Kit uses the WGS 84 GPS coordinate system, which meets most map development requirements outside the Chinese mainland, including:

  • Map display: Displays features such as buildings, roads, water systems, and Points of Interest (POIs).
  • Map interaction: Controls the interaction gestures and buttons on the map.
  • Map drawing: Adds location markers and various shapes.

Creating the Project

We use DevEco Studio to develop with Harmony OS. We can also use a Wearable watch or simulator to test our app.

You can follow the steps below to create our Wearable project on DevEco Studio.

  1. Follow the File > New >New Project path.

2. On the opened page, choose the Empty Ability template and click the Next button. If you want to use Map Kit in your project, you should make sure to choose Java.

3. On the page that opens, the necessary information about the project is filled and the project type and device information are selected. The project is created by clicking the Finish button.

Project Development

  1. Create your project on AppGallery Connect and make your necessary configurations.
  2. Download the agconnect-services.json file of your app. And add the agconnect-services.json file to the app’s root directory of your project.
  3. Open the app-level build.gradle file of your project and add the HMS Maps dependence.
  4. Enable Map Kit from Project Settings >Manage API.

5. Create and initialize MapView object.

6. Then create the layout for the map.

7. After that call the onStart(), onActive(), onInactive(), onBackground(), onForeground(), and onStop() methods of MapView in the corresponding methods in MainAbilitySlice.

8. Load the MapView object on your in MainAbilitySlice.

Conclusion

  • Before using the Map feature for HarmonyOS, make sure you have opened a Java project.
  • Do not forget to enable Map Kit from your app on AppGallery Connect.

References

--

--