Find the nearest Ispark with this app

Umit Kose
Huawei Developers
Published in
4 min readJul 16, 2020

Hi everyone,

In this tutorial I will explain you an app which provides Ispark points on the map using Huawei Map Kit, Location Kit,Direction API and Analytics Kit for now. In future post there will be Account Kit and Push Kit as well.

With this app users can see all ispark points on the Huawei map and users are able to navigate it which is the closest one. Also this app provides information about ispark points such as capacities, adresses and provinces. If user has Yandex map , it directly navigate to Yandex Navi app. If not, you will be redirected to App Gallery Yandex app page.

Let’s start with adding HMS Core to our application first. For this, you can follow the steps in the link below:

Huawei Map Kit

HMS Map Kit is a set of interfaces for map development in Android.The map data covers most countries outside China and supports multiple languages. You can easily add map related functions in your Android app.

Huawei Location Kit

Location Kit combines the GPS, Wi-Fi, and base station locations to help you quickly obtain precise user locations, build up global positioning capabilities, and reach a wide range of users around the globe.

Huawei Map Kit Direction API

The Direction API is a service that calculates directions between locations. You can search for directions for several modes of transportation, including driving, walking, or cycling.

Integration and Development

First, we start by adding the libraries we will use in our gradle file.

implementation 'com.huawei.hms:maps:4.0.1.302'
implementation 'com.huawei.hms:location:4.0.4.300'
implementation 'com.huawei.hms:hianalytics:5.0.1.300'
implementation 'com.huawei.agconnect:agconnect-crash:1.3.2.301'

These are also for Retrofit,Gson Converter and BottomSheet:

implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.trafi:anchor-bottom-sheet-behavior:0.13-alpha'

1 — Create Retrofit Interface and Api Service

2 — Create Model

I have created 2 models to parse data from retrofit response but its too much code to share in here. You will be able to find them in the project on Github.

3 — Initialize Location Provider and getLastLocation() Method

With this method, first we are checking to see if the user has given permission. Then we check GPS location is open or not. If everything is ok, then we check there is last location , if not then we create location request. After that we keep our latitude and longtitude values. Huawei map moves to our location and set enable to location button.

Check and Request Permission Methods:

4 — Adding markers to Huawei Map in onMapReady function

With the code above, we change the marker icons depends on parking capacity and add on the Huawei Map.

Define markers clusterable:

// Set markers clusterable
hmap.setMarkersClustering(true);

Note: It is more convenient than Google Map, just 1 line codes. in Google Map we would need to create CustomMarkerRenderer classes.

5 — Marker click event and show details of POI

6 — Show route on the Huawei Map

7 — Navigate to Yandex Map or AppGallery Page

If the user has Yandex Navi app , when user click to navigate button it direct you to app. If user has not, it navigates you to download Yandex Map app on AppGallery Connect.

App Screenshots

--

--