Huawei Implementation Series(Location Provider) — 1

Zehra Yılmaz
BiTaksi Product & Tech
2 min readSep 8, 2022

Hello everyone! I am back :) In this post, I’ll tell you how we’ve implemented Huawei Location Services for BiTaksi. Please don’t forget to follow up to be notified about the next posts.

Let’s start!

Create a Device Controller

First of all, we need to learn whether our device is supported by HMS or GMS; to do so, we are going to create a controller class having two methods. One is for controlling if the device is supported by HMS and the other one is for GMS.

Once we have the information about the supported service type, we will provide the related class for injection.

Create a Location Provider Interface

Now, we have device type to decide which device provider implementation will be used. Let’s see what’s in the location provider interface:

val subscribe: Flow<Location>

suspend fun lastLocation(): LatLon?

suspend fun askLocationPermission(): Result<Boolean>

subscribe:

as in the name, we will use this to subscribe current location provider callback.

askLocationPermission:

to use location services, we need users’ consent. we will use this method to ask permission.

lastLocation:

this is the method where we get location, so I will tell you about this in detail.

Huawei and Google services have different aspects of this method; I’ll start with getting GMS location:

locationProviderClient is the variable that we created using

LocationServices.getFusedLocationProviderClient(context)

We need to start with requesting location, createLocationRequest method does the job here after we are assured that location permission is granted, we call our client’s request method to get the last location and use a callback to collect the result.

We have a request method where you can set parameters according to your needs here.

FusedLocationProviderClient is a class of google location package; using this class, we call a method to get the location; this is where we get the last location and pass it to the callbacks.

We have exactly the same methods for Huawei implementation, just used different packages :)

That’s it! Now we have two different location providers working for both google play and pure HMS devices :)

--

--