At some point in career, you probably had to work on a project where you need to track a device’s location. Chances are before starting your work, you’ll spend quite some time going through blogs and documentation about location tracking, GPS tracking, and all those things. For new developers, google play services API can be the way to go. It contains several google related APIs such as maps, location, navigation, and many more. But sometimes when we want a bit more than just device tracking or location updates, the features provided by google play services might be a bit insufficient.
Purpose of this blog
The main purpose of this blog is to help new developers by bringing to their notice other libraries and APIs that are out there related to location tracking besides google play services. I will also be discussing how and what features of HERE SDK did I use personally in the Wolfmatrix project. I believe the readers will benefit from this article as it not only puts light on GPS tracking in Android and HERE’s location library along with its usage but also saves you a lot of time spent on going through several blogs and documentation to find out what you actually need for your project. In this blog, I have mentioned why and how I used HERE’s location library. After reading this, readers will have an idea of what HERE library is and in what scenarios it’ll be handy.
GPS tracking is a hot topic these days in almost every app. Most mobile apps have some sort of tracking mechanism for tracking the user’s location or their movement. These are extremely useful in many cases like when your phone has been lost or stolen.
Be it tracking vehicle movement or tracking some waiter’s journey along the way for delivering food for the restaurant business, their position is continuously traced and tracked. Clients track their driver’s journey for many reasons. It helps the company to decrease the wear and tear of the vehicles, improve driving safety, faster emergency response times, accurate and auditable service performance records, etc. It, in turn, reduces vehicle and equipment maintenance costs, tampering and thefts.
GPS tracking in Android
Earlier, getting location was very easy with a couple of API calls. Later to provide more accurate locations and to optimize the battery usage, Android introduced set APIs (google play services for location) google play that should be combined to get the best results from the location API. In Android, the most common library to get users location is:
It uses Fused Location API that combines signals from GPS, Wi-Fi, and cell networks, as well as an accelerometer, gyroscope, magnetometer and other sensors to provide more accurate results. An app can get the location update based on several criteria like location setting, update interval, fastest update interval and priority.
“Why did I choose HERE location service for my project instead of Google location services?”
“Google play service library doesn’t always fits in your project.”
The android app that I had to work on required a feature where the driver’s location had to be tracked continuously. Plus it had to send a notification once the driver gets in or out of the pre-set virtual geofence. Working with Google’s location service, I felt that its smallest interval for location update is a bit large for me. And it was not accurate enough too. Now the problem is that the vehicle would be moving at a high speed, say 50 mph (that would be around 80 kmph) but the geofence that was set usually only had a radius of 50 to 60 meters. The rate of getting location updates of the driver should be very high, in our case say every 1 to 2 seconds because the vehicle moving at 80 kmph would cross the geofence of a 60m radius in no time.
We can create geofence using same google gms play services with a few boilerplate codes. Now the major area of concern is: firstly, getting the location updates of driver’s vehicle at short intervals and secondly, creating geofence of a certain radius and to get notified when the driver gets in or out of the geofence at high speed.
“I needed something that requires less code.”
So I needed some sort of mechanism that can handle both of the aspects with less fuss without having to worry about code optimization and device performance issues. Google location service API has usage limits of about 100 geofences per device which was not enough for me. Additionally, running google play services app on the background can cause battery drainage. And my app had to continuously listen for location changes in the background.
There was one more reason why I had to search for an alternate solution. In google services documentation, its mentioned that for best results, the minimum radius of the geofence should be set between 100-150 meters. But our project had set a benchmark for geofence radius of minimum 50 meters. After going through these numbers of drawbacks, I had to look for another approach for my project. That’s when I came across “HERE” API.
“Always choose a framework that suits your project”
HERE API for Android
HERE is a complete location-based API and SDKs package for developers with features highly accurate and interactive global maps, high precision location updates, device tracking, turn by turn navigation with real-time and historical traffic information, mobile navigation solutions, and many more. HERE has everything that I needed for my app. It is not completely free of course with about 250K transactions per month. But given that it provides positioning SDK for android and IOS for users to retrieve location updates, I was happy to pay the price.
HERE positioning SDK can provide rich location features based on Wi-Fi, Cellular, and BT network-based positioning, including features like Online Outdoor positioning, Online-Offline Hybrid Outdoor positioning, Indoor positioning, Private Indoor positioning with fairly small intervals with the bulk of the work done by the SDK itself. Its advanced features include:
- Automatic positioning method switching between satellite-based (GNSS), Wi-Fi, Bluetooth, and cellular network positioning. That provided the best possible position information using the available methods.
- HERE Indoor Positioning supports both private and public data. You can have a private venue that is mapped through HERE Private Venues or your own custom indoor map, with the indoor location information being only available for your applications. In contrast, indoor location information for public venues is available for all HERE SDK users with an appropriate license.
- Global positioning coverage and data hosting infrastructure for optimal availability, reliability, and user experience.
Working with HERE
1. Getting location from Here’s positioning SDK
As mentioned in its documentation, HERE positioning SDK gives highly accurate location along with other information. Some of them are altitude accuracy, speed and the timestamp in a reasonably short interval of time in comparison to Google’s location service. To obtain the HERE Android SDK, register or login with your HERE account from site developer.here.com, find the section for HERE Android SDK Premium Edition and click on Generate App ID and App Code to obtain your app credentials and the SDK download link. Now download the HERE android SDK library from site developer.here.com and click on Get Started for Free to create the first HERE project.
- Register or sign in to your HERE Account.
- Agree to the HERE Terms and Conditions.
- On the Platform Activation screen, follow the link to download the HERE Android SDK as a Zip package.
Using HERE positioning SDK, I can get the location updates of the driver’s vehicle at certain intervals. Now in order to produce notification every time the driver’s vehicle entered or exited the geofence, we have to continuously send driver’s location to HERE server. In my project, the part of geofence creation is done through the backend. So for simplicity purpose, I will just explain the parts focusing on Android.
2. Sending location to HERE server
Now that we’re done with getting the location updates, the next part is to send those location updates to the server. Previously I had used HERE positioning SDK to get the location updates of the driver’s vehicle; now for sending these locations to the HERE server, I am using HERE’s GPS tracking API. It provides yet another feature, tracking API in which it exposes a set of REST APIs and client libraries. That enables location tracking and geofencing for a variety of device form-factors including small-footprint (small memory and processing power) devices. I’ve used android’s retrofit library to call API for sending location you can use anything you want.
Like I mentioned previously, the geofence creation part is done through our backend. All I had to focus on is sending a location from the device on a regular basis. Now before sending locations to HERE API, we have to register our device to HERE server. It will help HERE to track our particular device while sending notifications. I’m not going to explain the process of device registration as it is well explained in HERE tracking documentation
3. And Finally
Now once the task of geofence creation, device registration and location sending is done, the rest of the work is done by HERE. HERE continuously analyzes the device’s location and checks if the device enters or exits geofence that it is registered to.
The event when the device enters or exits the geofence is termed as a transition event. These transition events are stored in the transition log. These logs include all the details of events including where a device almost crossed a geofence boundary. A webhook notification is created every time a device enters or exits an associated geofence. We can list all the devices associated with that particular HERE account and all geofences being created. We can also list all the geofences that a particular device is associated with, all transition events and many more. From here we can monitor and analyze the devices, geofences and log transitions in HERE’s graphical user interface.
My experience with HERE
Working with HERE was like a roller coaster ride. It has provided so many features whereby HERE itself does the bulk of the work. That leaves just the task of configuring devices with HERE account, authorizing user, creating geofences and sending locations.
Even though working with HERE was easy for me, it was a bit tricky to kick-start it. I had to go through their documentation several times before getting a hold of what I was actually looking for in HERE. Their documentation is quite vast since they have a number of features. So it could be a bit tricky to get what we’re looking for from their documentation. Of numerous features provided by HERE, my android app only required HERE’s positioning SDK and HERE GPS tracking API. So this article solely focuses on these two features. However, HERE has numerous other features like street maps, navigation, routing, geocoder, places, etc which you can definitely have a look at.
Another aspect I would like to mention
After copying HERE’s AAR file to my project, my APK size ballooned from 3MB to 44MB. Its compressed AAR file contains a number of libraries in SO (shared object) format. All of these libraries go inside the APK. To reduce the size of my APK, the first thing I did was removing few unused libraries like libsMAPSJNI.so since my app did not have anything to do with maps; all I was using was positioning feature. Doing this caused my app to give an error message of libraries missing and all features of HERE stopped working. I guess HERE required it’s all libraries to be present in the app regardless of what feature you are using which I found a bit strange.
Eventually, I had to configure APK for multiple ABIs generating separate APK for each ABI using splits block. While working in HERE, you might get a bit of a hard time searching for HERE related questions and answers in StackOverflow, all you can do is put your questions in the issues section of HERE GitHub.
So what’s the ultimate location-based platform available out there?
Now, of course, the question arises, is HERE the best platform out there for location and GPS tracking? The answer is definitely no. There are so many location related libraries and frameworks available for different platforms. Interestingly, each framework has something better than the other or something that better suits your problem. HERE framework suited for my project. It may not be the best solution for you.
For me, working with HERE has been nothing but fun. Although I just used a couple of features of vastly spread HERE platform, I gained so much knowledge about location GPS tracking and other cool features that HERE has to offer. I strongly suggest you guys explore and try different other features of HERE like navigation, routing, maps, etc. Not just HERE, there are so many location-based frameworks and libraries for GPS tracking available out there. Map box, radar, etc are some of them. Explore, learn new things, and enjoy technology!