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.
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.
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.
1. Unity Engine (Installed in the system)
2. Huawei phone
3. Visual Studio 2019
4. Android SDK & NDK (Build and Run)
1. Sign In and Create or Choose a project on AppGallery Connect portal.
2. Navigate to Project settings and download the configuration file.
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.
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
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) 22.214.171.1240 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.
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.