Select Page

Knowing a user’s location in an Android app can be extremely useful. Users take their devices everywhere and are constantly using them on the go, and as developers, we can capitalise on that by providing a more contextual experience based on their current location.

My previous post explains, how to get users current location using FusedLocationProviderApi with step by step guide. In this part, we’ll discuss how to simplify the process with the help of LocationHelper.

LocationHelper is nothing but a util class which is taken care of finding users location. Using this we can get the current location within 5 minutes and also it will do the runtime permission check.

How to use LocationHelper?

LocationHelper implementation process is so simple.

1. Create an instance of the utility class and pass the Activity as a parameter.

   LocationHelper locationHelper;
   locationHelper=new LocationHelper(this);

2. For checking the permission during runtime, call the following method with the help of the above-created instance.


3. At next implement the needed callbacks into the Activity.

public class MyLocationUsingHelper extends AppCompatActivity implements ConnectionCallbacks,

4. Redirect the implemented methods to the util function, then only it will automatically do the needed background works.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

// Permission check functions
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    // redirects to utils


5. Then handle the ConnectionCallback implemented methods using the following snippet.

 * Google connection callback methods
public void onConnectionFailed(ConnectionResult result) {
    Log.i("Connection failed:", "" + result.getErrorCode());

public void onConnected(Bundle arg0) {

    // Once connected with google api, get the location

public void onConnectionSuspended(int arg0) {


6. To check the availability of Google play service, use checkPlayServices() method. If it’s available then build the GoogleAPiClient using the below code.

// check availability of play services
if (locationHelper.checkPlayServices()) {
    // Building the GoogleApi client


7. Once all the above steps are done, then we can easily get the location and also the address using the simple function call.

Location mLastLocation;


if (mLastLocation != null) {
    latitude = mLastLocation.getLatitude();
    longitude = mLastLocation.getLongitude();

    Address locationAddress;



That’s it. Now you have the current location and also the address. Happy coding 🙂

I created a sample project on GitHub to demonstrate the things covered in this article.

View on GithubDownload .zip

Feel free to comment and share, keep watching this space get more updates on Android Stuff!


Jaison Fernando

Android Developer at NFN Labs