Expert: Xamarin Android HMS Map Kit Integration With Polyline in SampleApp

HMS Core Map SDK is a set of APIs for map development in Android. The map data covers most countries outside China and supports multiple languages. The Map SDK uses the WGS 84 GPS coordinate system, which can meet most requirements of map development outside China. You can easily add map-related functions in your Android app, including

Manoj Kumar
5 min readApr 9, 2021

Overview

In this article, I will create HMS Map Kit based Demo App which highlights the use case of Basic Map and Polyline. I have integrated HMS Map Kit which is based on Cross-platform Technology Xamarin.

HMS Map Kit Service Introduction

HMS Core Map SDK is a set of APIs for map development in Android. The map data covers most countries outside China and supports multiple languages. The Map SDK uses the WGS 84 GPS coordinate system, which can meet most requirements of map development outside China. You can easily add map-related functions in your Android app, including:

1. Map display: Displays buildings, roads, water systems, and Points of Interest (POIs).

2. Map interaction: Controls the interaction gestures and buttons on the map.

3. Map drawing: Adds location markers, map layers, overlays, and various shapes

Prerequisite

1. Xamarin Framework

2. Huawei phone

3. Visual Studio 2019

App Gallery Integration process

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

2. Navigate to Project settings > download the configuration file and Add SHA-256 key.

3. Navigate to General Information > Data Storage location.

4. Navigate to Manage APIs > enable APIs to require by an application.

Xamarin Map Kit Setup Process

1. Download Xamarin Plugin all the aar and zip files.

2. Open the XHms-Map-Kit-Library-Project.sln solution in Visual Studio.

3. Navigate to Solution Explorer and Right-click on jar Add > Existing Item and choose aar file which downloads in Step 1.

4. Right-click on added aar file then choose Properties > Build Action > LibraryProjectZip.

Note: Repeat Step 3 & 4 for all aar file.

5. Build the Library and make dll files.

Xamarin App Development

1. Open Visual Studio 2019 and Create a new project.

2. Navigate to Solution Explore > Project > Assets > Add Json file.

3. Navigate to Solution Explore > Project > Add > Add New Folder.

4. Navigate to Folder(created) > Add > Add Existing and add all DLL files.

5. Right click > Properties > Build Action > None.

6. Navigate to Solution Explore > Project > Reference > Right Click > Add References then Navigate to Browse and add all DLL files from the recently added Folder.

7. Added reference then click Ok.

MainActivity.cs

This activity display type of map in 2 buttons.

MapViewDemoActivity.cs

This activity display a basic view of Huawei Map.

PolylineDemoActivity.cs

This activity draws a polyline between the two points in the Huawei map.

Xamarin App Build Result

1. Navigate to Solution Explore > Project > Right Click > Archive/View Archive to generate SHA-256 for build release and Click on Distribute.

2. Choose Distribution Channel > Ad Hoc to sign apk.

3. Choose Demo Keystore to release apk.

4. Build succeed and Save apk file.

5. Finally Result.

Tips and Tricks

1. Xamarin requires the ADB daemon to be started over port 5037. If the ADB daemon runs on a different port, Visual Studio will not be able to detect your device.

2. Map Kit needs to read appid and other attributes from the AppGallery Connect configuration file. In some conditions, Map Kit can’t read appid.

Conclusion

In this article, we have learned how to integrate HMS Map Kit in Xamarin based Android application. In this application, I have explained the use case of Map kit with Polyline draw.

Thanks for reading this article.

Be sure to like and comments on this article, if you found it helpful. It means a lot to me.

References

Xamarin Map Kit Plugin

--

--

Manoj Kumar
Manoj Kumar

No responses yet