Track the Motion using Huawei Map Kit and Location Kit in Android app (Kotlin)

Murali Akula
4 min readJan 21, 2022

Introduction

In this article, we can learn how to track the closer look of the user when the user is in running mode. To track the motion capabilities used Huawei Location Kit and Map kit and you can integrate into your app. Use Location Kit to obtain the user’s current location and real-time location updates. Use Map Kit to display the user’s current location, and draw a motion track based on the real-time location updates. Use the mock location function in Location Kit to reproduce the motion track.

Map Kit

Map Kit covers map data of more than 200 countries and regions, and supports over 70 languages. User can easily integrate map-based functions into your apps using SDK. It optimizes and enriches the map detail display capability. Map Kit supports gestures including zoom, rotation, moving and tilt gestures to ensure smooth interaction experience.

Location Kit

Location Kit combines the GPS, Wi-Fi and base station location functionalities in your app to build up global positioning capabilities, allows to provide flexible location-based services targeted at users around globally. Currently, it provides three main capabilities: fused location, activity identification and geo-fence. You can call one or more of these capabilities as required.

Requirements

1. Any operating system (MacOS, Linux and Windows).

2. Must have a Huawei phone with HMS 4.0.0.300 or later.

3. Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.

4. Minimum API Level 24 is required.

5. Required EMUI 9.0.0 and later version devices.

How to integrate HMS Dependencies

1. First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a Huawei ID.

2. Create a project in android studio, refer Creating an Android Studio Project.

3. Generate a SHA-256 certificate fingerprint.

4. To generate SHA-256 certificate fingerprint. On right-upper corner of android project click Gradle, choose Project Name > Tasks > android, and then click signingReport, as follows.

Note: Project Name depends on the user created name.

5. Create an App in AppGallery Connect.

6. Download the agconnect-services.json file from App information, copy and paste in android Project under app directory, as follows.

7. Enter SHA-256 certificate fingerprint and click Save button, as follows.

Note: Above steps from Step 1 to 7 is common for all Huawei Kits.

8. Click Manage APIs tab and enable Map Kit and Location Kit.

9. Add the below maven URL in build.gradle(Project) file under the repositories of buildscript, dependencies and allprojects, refer Add Configuration.

10. Add the below plugin and dependencies in build.gradle(Module) file.

11. Now Sync the gradle.

12. Add the required permission to the AndroidManifest.xml file.

Let us move to development

I have created a project on Android studio with empty activity let us start coding.

In the MainActivity.kt we can find the business logic.

In the MapActivity.kt we can find the business logic.

Create GpsDataSaver.kt class for GPS Data server.

Create PathBean.kt class for paths and time track.

In the activity_main.xml we can create the UI screen.

In the activity_map.xml we can create the UI screen.

Demo

Tips and Tricks

1. Make sure you are already registered as Huawei developer.

2. Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.

3. Make sure you have added the agconnect-services.json file to app folder.

4. Make sure you have added SHA-256 fingerprint without fail.

5. Make sure all the dependencies are added properly.

Conclusion

In this article, we have learned how to track the closer look of the user when the user is in running mode. To track the motion capabilities used Huawei Location Kit and Map kit and you can integrate into your app. Use Location Kit to obtain the user’s current location and real-time location updates. Use Map Kit to display the user’s current location, and draw a motion track based on the real-time location updates. Use the mock location function in Location Kit to reproduce the motion track.

I hope you have read this article. If you found it is helpful, please provide likes and comments.

Reference

Map Kit

Location Kit

--

--