Location tracking and monitoring have seen a surge in modern application development with various services such as Uber heavily relying on location services that require consistency and accuracy. With businesses and corporations requiring location information and monitoring of their various assets, delivering comprehensive location solutions has been a tricky science for many developers.

Identifying the growing demand for a convenient location providing service Google introduced the Fused Location Provider API. This article will focus on using the API to track a user’s real-time location using an android application and through the example demonstrate the beauty of the API.

The API focuses on providing location information using a combination of a device’s GPS, Wi-Fi and internal sensors. The main selling point is that it decides in what combination to use these three resources based on the request parameters provided. In this context managing these resources is abstracted from the developer.

A simple use case to demonstrate the capacity of the API is tracking the movement of an individual walking towards a building, entering it and then leaving. In this scenario when the person is outdoors, the GPS service will function well. However, as he enters the building the GPS signal may drop. The Fused Location Provider handles the above scenario by tracking the location outdoors via GPS and when the GPS signal drops within the building, it utilizes Wi-Fi. During the switching process from GPS to Wi-Fi, to provide a smoother transition, the device’s internal sensors are used to predict the movement. In this manner, the management of available resources to provide reliable location services in a battery efficient manner is the true power of the API.

Integrating the API into your android application is a simple process. In this example, we will walk through the necessary steps required to build a simple location tracking application.

First, create an android project in Android Studio and within the application’s build.gradle file, ensure the following dependency is present:

dependencies{
   implementation ‘com.google.android.gms:play-services:11.8.0’
}

Secondly, within the Manifest file you must provide either the Fine or Coarse location permission by adding the below snippet:

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

Now, create instances of FusedLocationProviderClient, **LocationRequest**and **LocationCallBack**in your activity.

private FusedLocationProviderClient fusedLocationClient;

private LocationRequest locationRequest;
private LocationCallback locationCallback;
@Override
protected void onCreate(Bundle savedInstanceState) {
      fusedLocationClient =       LocationServices.getFusedLocationProviderClient(this);
   }
}

#google-maps #android #android-app-development #google #fused-location-provider #modern

Real-Time Location Tracking Using Google’s Fused Location Provider API
4.95 GEEK