Integration of Huawei Location Kit in Unity
By: Manoj Kumar
Tags: Huawei, Unity, Hms, Location, Game Development

Integration of Huawei Location Kit in Unity

Location Kit allows user enabling their game to get quick and accurate user locations and expand global positioning capabilities by using GPS, Wi-Fi, and base station locations. Manoj Kumar Dec 23, 2020·4 min read

Overview

In this article, I will create a demo game and integrate Huawei Location Kit. I will display the user’s current location in coordinates and also user can share his location to other users in-game. I will cover every aspect of Location kit in unity so that user can easily integrate Location Kit in his Game.

Service Introduction

Location Kit allows user enabling their game to get quick and accurate user ocations and expand global positioning capabilities by using GPS, Wi-Fi, and base station locations.

Location Kit combines the GNSS, Wi-Fi, and base station location functionalities into your game to build up global positioning capabilities, allowing you to provide flexible location-based services for global users. Currently, it provides three main capabilities: fused location, activity identification, and geofence. You can call one or more of these capabilities as needed.

1. Fused location: Provides a set of easy-to-use APIs for your app to quickly obtain the device location based on the GNSS, Wi-Fi, and base station location data.

2. Activity identification: Identifies user motion status through the acceleration sensor, cellular network information, and magnetometer, helping you adapt your app to user behaviour.

3. Geofence: Allows you to set an interesting area through an API so that your app can receive a notification when a specified action (such as leaving, entering, or staying in the area) occurs.

Prerequisite

1. Unity Engine (Installed in the system)

2. Huawei phone

3. Visual Studio 2019

4. Android SDK & NDK (Build and Run)

Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Navigate to Project settings and download the configuration file.

Game Development

1. Create a new game in Unity.

2. Now add game components and let us start game development.

3. Download HMS Unity Plugin from below site.

https://github.com/EvilMindDevs/hms-unity-plugin/releases

4. Open Unity Engine and import the downloaded HMS Plugin.

Choose Assets > Import Package> Custom Package

5. Choose Huawei > App Gallery.

6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.

7. Create Huawei Location Kit based scripts.

I have created LocationManager.cs file in which integrated Huawei location which gets the user’s current location and shares their location to other users.

Click on LocationManager.cs and open in Visual Studio 2019

Result

Let us build the apk and install in android device.

Tips and Tricks

1. HMS plugin v1.2.0 supports 7 kits.

2. Ensure that you have installed HMS Core (APK) 3.0.0.300 or later.

3. It is recommended that the geofence radius should be minimum of 200 meters. Precision cannot be assured if the geofence radius is less than 200 meters.

4. User can share their location with other game’s user.

Conclusion

In this article, we have learned how to integrate Huawei Location Kit in Unity-based Game.

User can get their location in coordinates and share his/her location to other users in the game.

Thanks for reading this article. Be sure to like and comments to this article if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050706106