Introduction to Huawei Location kit with React Native

Neha Jeswani
4 min readJan 29, 2021

HMS Location Kit makes it easy by implementing the complex concept of human computer interaction to build an API. Which is built on top of the sensors available in a device.

In the previous article we learnt about two major capabilities of HMS Location Kit (Fused location and Location semantics).

This article will be focusing on other two capabilities provided by HMS Location Kit.

Activity Identification

Have you ever thought how does an application tells you the miles covered when you walk or run?

or

How does an application tells you how long will it take for you to cover a particular distance when you choose a transport method?

Interesting

Activity identification or Activity recognition is prodigious subject of HUMAN COMPUTER INTERACTION which studies the behavior of a human/agent or activity performed with the help of computer science.

HMS Location Kit makes it easy by implementing the complex concept of human computer interaction to build an API. Which is built on top of the sensors available in a device.

Activity Identification API automatically detects activities by periodically capturing the short streams of sensor data and process them to provide filtered information which can be used for any application.

Implementing Activity Identification API

Prerequisite

Please follow previous article for required setup and dependencies.

https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201249423429900180&fid=0101187876626530001&pid=0301251576252550745

Permission

Below permission is require to be added in the Manifest file

<uses-permission android:name=”android.permission.ACTIVITY_RECOGNITION” />

Activity Identification

CreateActivityIdentification method is used for initializing the Activity Identification services.

Once the Activity identification is initialized, this required to be removed also.

removeActivityIdentification can be used to remove the call back.

createActivityIdentificationUpdates

To use the activity identification service, you need to register receiving of activity identification updates to check the current user status, such as walking, bicycling, and motionless.

This can be achieved as below

addActivityIdentificationEventListener is a handler which is required to listen and receive data from activity identification events.

removeActivityIdentificationEventListener is required to remove the define listener

Activity Conversion

When there is a change in the activity let’s say from walking to running or running to walking, activity conversion methods are being used to read the changes.

createActivityConversionUpdates method is used to detect the activity conversions.

deleteConversionUpdates method is used to remove the conversion updates.

addActivityConversionEventListener acts a receiver and listen and handles any conversion updates.

removeActivityConversionEventListener is used to unregister the call backs for activity updates.

Geofence

Geofence is a virtual perimeter around a physical location.

Geofencing is very powerful tool using which virtual experience can be connected with the world’s physical location.

It works as a virtual boundary with respect to the physical location.

HMS Location Kit provides the geofence API for many good reasons:

An application can have the geofencing to get notified if any theft happens within defined boundaries.

A business can implement the geofencing for them to notify the customers with in the surroundings.

There are many possibilities to use the Geofence API.

Implementing Geofence API

geofencebuilder is an object to defined the geofence.

This can be achieved as below.

Geofence List

CreateGeofenceList is the method, responsible for adding a geofence around a location.

It takes below three arguments ;

Geofences: List of geofences to be added

Conversions: Initial conversions

Coordinate Type: Type of coordinate

deleteGeofenceList is the method, responsible for already added geofence.

addGeofenceEventListener method is used to subscribe geofence updates.

It takes a callback function that is continuously called with geofence data. You need to register for updates first by using the createGeofenceList function.

removeGeofenceEventListener method removes the event listener that is added by addGeofenceEventListener.

geofenceData object is useful to read error codes.

Results

FAQ’s

https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/location-faq

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/location-description-rn-v4

Conclusion

HMS Location Kit can be used in various real time scenarios to improvise the day to day life and can add value to various business solutions.

--

--