Google’s Fused Location API for Android

17 / Jul / 2014 by Himanshu Kumar Singh 12 comments

For android applications, the Fused Location Provider intelligently manages the underlying location technology and gives us the best location according to our needs.

We could choose one of the location providers (network or GPS) and request location updates or set up proximity alert. But there were two main challenges with this approach:

1. In case we need to define precise location, we had to switch between network and GPS location providers (as GPS doesn’t work indoors)
2. Proximity alerts were used to notify a user about proximity to a location, and this took its toll on the battery life

Advantages of Using API

1. Simple APIs: Lets us specify high-level needs like “high accuracy” or “low power”, instead of having to worry about location providers.
2. Immediately Available: Gives our apps immediate access to the best, most recent location
3. Power-Efficiency: Minimizes power usage by the apps. Based on all incoming location requests and available sensors, fused location provider picks the most efficient way to meet those needs.
4. Versatility: Meets a wide range of needs, from foreground uses that need highly accurate location to background uses that need periodic location updates with negligible power impact.

Note : Make sure Google Play services is properly installed and working in our device. Please don’t test this location API in an emulator as this does not work.

Ways to Use

1. Import Google Play services from Android SDK (../sdk/extras/google/google_play_service/libproject/google-play-services_lib) as a library in our application

Declare the permission in the manifest file.

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

Android has two location permissions, ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.

The permissions that we choose affects the accuracy of the location updates we receive. For example, if we request only coarse location permission, Location Services obfuscates the updated location to an accuracy that is roughly equivalent to a city block.


3. There is two main class which are most important in this server
3.1 : Stores the current instantiation of the location client
3.2 : A data object that contains quality of service parameters for requests to the LocationClient

4. Location Service Callbacks : Before we request location updates, we must first implement the interfaces that Location Services uses to communicate connection status to our app: Specifies methods that Location Services calls when a location client is connected or disconnected


new GooglePlayServicesClient.ConnectionCallbacks() {

public void onDisconnected() {
// TODO Auto-generated method stub


public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub



[/java] : Specifies a method that Location Services calls if an error occurs while attempting to connect the location client.


new GooglePlayServicesClient.OnConnectionFailedListener() {
public void onConnectionFailed(ConnectionResult arg0) {

How to Use

1. Connecting LocationClient to Google API. After connecting locationClient, we are able to get location
2. Retrieving the current location
3. Retrieving the location update at particular time interval or particular distance or both.

1. Connecting LocationClient to Google API:

// Create a new global location parameters object
LocationRequest mLocationRequest = LocationRequest.create();

//Set the update interval

// Use high accuracy

* LocationClient(arg1, arg2 , arg3)
* arg1 :Context
* arg2 : ConnectionCallbacks
* arg3 :OnConnectionFailedListener

LocationClient mLocationClient = new LocationClient(arg1, arg2 , arg3);

* Note: connect() method will take some time. So for getting the
* current location or getting location update at particular inteval,
* we have to wait for the connectin established.


During the Google IO presentation, a chart was presented showing effect of different priorities of the recognition algorithm as tested multiple times on Galaxy Nexus

Priority Typical location
update interval
Battery drain
per hour (%)
HIGH_ACCURACY 5 seconds 7.25% ~10 meters
BALANCED_POWER 20 seconds 0.6% ~40 meters
NO_POWER N/A small ~1 mile

2. Retrieving The Current Location :

Location myLocation = mLocationClient.getLastLocation();
* Now MyLocation object has all infromation
* like latitude,longitude etc.

The return value is the best, most recent location, based on the permissions our app requested and the currently-enabled location sensors.

Before we create the location client, implement the interfaces that Location Services uses to communicate with our app:

Reference :

3. Retrieving Location Updates : To get periodic location updates from location services, we send a request using a location client. Depending on the form of the request, location services either invokes a callback method and passes in a location object, or issues an intent that contains the location in its extended data. The accuracy and frequency of the updates are affected by the location permissions we’ve requested and the parameters we pass to location services with the request.

LocationListener listener = new LocationListener() {

public void onLocationChanged(Location location) {
// Report to the UI that the location was updated
String msg = "Updated Location: " +
Double.toString(location.getLatitude()) + "," +
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();



Reference :

You might also like reading our blog on Background Location Updates on Android


comments (12)

  1. sunisha

    1) I’m getting speed as 3.0 something. But I am in the same place and am not traveling anywhere, so from where is the speed coming from? I am testing with a Samsung device and a Motorola device. The problem is appearing on the Motorola device.
    2) I’m setting the interval with: mLocationRequest.setInterval(1000 * 60); But the problem shows up on the Motorola device before 60 seconds which is updating (approximately at 30 second)

    1. vinod singh

      Hi Himanshu,
      may i know which method we can use to get location after a specific distance like after each 100 meter.


    1. surya prakash sahu

      Emulator dont have the gps tracker.To work you have to use it in real device,i.e mobile phones.

    2. surya prakash sahu

      How to get update with specific time and distance??
      You did’nt used anything in your code for that.
      please reply as soon as possible


Leave a Reply

Your email address will not be published. Required fields are marked *