You just need to include this in your build.gradle file:

implementation "com.google.android.gms:play-services-location:15.0.1"

or if you're not using latest gradle version:

compile "com.google.android.gms:play-services-location:15.0.1"

Note: It's recommended to use Google Play services version 15.0.1 or higher, which includes bug fixes for this class. More details here.

https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderClient

Answer from Reza on Stack Overflow
🌐
Akaver
courses.taltech.akaver.com › 13 - fused location
13 - Fused location | Native Mobile Applications - Courses
March 29, 2026 - package ee.taltech.permissionsdemo ....ServiceCompat import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationCallback import com.google.android.gms.......
🌐
Google
developers.google.com › google play services › fusedlocationproviderclient
FusedLocationProviderClient | Google Play services | Google for Developers
October 31, 2024 - FusedLocationProviderClient is the main entry point for interacting with the Fused Location Provider (FLP) and requires either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
🌐
Android Developers
developer.android.com › core areas › sensors and location › get the last known location
Get the last known location | Sensors and location | Android Developers
private lateinit var fusedLocationClient: FusedLocationProviderClient override fun onCreate(savedInstanceState: Bundle?) { // ...
🌐
Google
developers.google.com › location-context › fused-location-provider
Fused Location Provider API | Google for Developers
Get an overview of this battery-efficient location API and links to guides about how to use it.
Top answer
1 of 2
36

You just need to call mFusedLocationClient.removeLocationUpdates(mLocationCallback) in onPause() of your Activity. However, there is a bit more to it than just that.

Use member variables for the FusedLocationProviderClient and LocationRequest in your main activity:

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;

public class MainActivity extends AppCompatActivity
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

    FusedLocationProviderClient mFusedLocationClient;
    LocationRequest mLocationRequest;

    //..........

Use a member variable for the LocationCallback as well:

LocationCallback mLocationCallback = new LocationCallback(){
    @Override
    public void onLocationResult(LocationResult locationResult) {
        for (Location location : locationResult.getLocations()) {
            Log.i("MainActivity", "Location: " + location.getLatitude() + " " + location.getLongitude());

        }
    };

};

Then, assign mFusedLocationClient in onCreate() :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    requestLocationUpdates();

    //...............
}

Then in onResume(), if theFusedLocationProviderClient is set up, then use it.

@Override
public void onResume() {
    if (mFusedLocationClient != null) {
        requestLocationUpdates();
    }
}

public void requestLocationUpdates() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(120000); // two minute interval
    mLocationRequest.setFastestInterval(120000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
    }
}

And finally, in onPause(), call removeLocationUpdates():

@Override
public void onPause() {
    super.onPause();
    if (mFusedLocationClient != null) {
        mFusedLocationClient.removeLocationUpdates(mLocationCallback);
    }
}
2 of 2
1

After getting location just remove mFusedLocationClient.removeLocationUpdates as he mentioned in above answers.

if (mFusedLocationClient != null) 
        mFusedLocationClient.removeLocationUpdates(mLocationCallback);

Looper will be called requestLocationUpdates until you remove it.

In my problem, I did as I mention above. Below is my code.

  mFusedLocationClient.getLastLocation()
                    .addOnSuccessListener(new OnSuccessListener<Location>() {
                        @Override
                        public void onSuccess(Location location) {
                            // GPS location can be null if GPS is switched off
                            if (location != null) {

                                mLocation = location;

                                if (mFusedLocationClient != null) {
                                    mFusedLocationClient.removeLocationUpdates(mLocationCallback);
                                }
                          } else {
                                startLocationUpdates();
                           }
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(HomeActivity.this, "Error trying to get last GPS location", Toast.LENGTH_SHORT).show();
                            e.printStackTrace();
                        }
                    });

and below is my requestLocationUpdates so I will get a request until the location is available.

private void startLocationUpdates() {
        mSettingsClient.checkLocationSettings(mLocationSettingsRequest)
                .addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
                    @Override
                    public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
                        Log.i(TAG, "All location settings are satisfied.");

                        getPackageManager().checkPermission(Manifest.permission.ACCESS_FINE_LOCATION, getPackageName());
                        mFusedLocationClient.requestLocationUpdates(mLocationRequest,
                                mLocationCallback, Looper.myLooper());
                        getLastLocationNewMethod();
                    }
                })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        int statusCode = ((ApiException) e).getStatusCode();
                        switch (statusCode) {
                            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                                Log.i(TAG, "Location settings are not satisfied. Attempting to upgrade " +
                                        "location settings ");
                                try {
                                    ResolvableApiException rae = (ResolvableApiException) e;
                                    rae.startResolutionForResult(HomeActivity.this, 0x1);
                                } catch (IntentSender.SendIntentException sie) {
                                    Log.i(TAG, "PendingIntent unable to execute request.");
                                }
                                break;
                            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                                String errorMessage = "Location settings are inadequate, and cannot be " +
                                        "fixed here. Fix in Settings.";
                                Log.e(TAG, errorMessage);
                                Toast.makeText(HomeActivity.this, errorMessage, Toast.LENGTH_LONG).show();
                                //  mRequestingLocationUpdates = false;
                        }
                        getLastLocationNewMethod();  // this method is where I can get location. It is calling above method. 
                    }
                });
    }

Note: For more information here is GitHub Repo LINK

🌐
Mapsindoors
docs.mapsindoors.com › sdks-and-frameworks › android › user-positioning › using-google-fused-location-provider
Using Google Fused Location Provider | MapsIndoors® Documentation
April 28, 2026 - class GPSPositionProvider(context: Context): MPPositionProvider { private var fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(context) private var mLatestPosition: MPPositionResultInterface?
Find elsewhere
🌐
Codepath
guides.codepath.org › android › Retrieving-Location-with-LocationServices-API
Retrieving Location with LocationServices API | Android Development | CodePath Guides
public void getLastLocation() { // Get last known recent location using new Google Play Services SDK (v11+) FusedLocationProviderClient locationClient = getFusedLocationProviderClient(this); locationClient.getLastLocation() .addOnSuccessListener(new OnSuccessListener<Location>() { @Override public void onSuccess(Location location) { // GPS location can be null if GPS is switched off if (location != null) { onLocationChanged(location); } } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d("MapDemoActivity", "Error trying to get last GPS location"); e.printStackTrace(); } }); }
🌐
Medium
medium.com › @myofficework000 › real-time-location-tracking-made-easy-with-fused-location-provider-43de6437fbd3
Real-Time Location Tracking Made Easy with Fused Location Provider | by Abhishek Pathak | Medium
October 15, 2024 - @SuppressLint("MissingPermission") private fun requestCurrentLocation() { val currentTask: Task<Location> = fusedLocationProviderClient.getCurrentLocation( PRIORITY_HIGH_ACCURACY, cancellationTokenSource.token ) currentTask.addOnCompleteListener { task: Task<Location> -> if (task.isSuccessful && task.result != null) { val result: Location = task.result binding.locationUpdate.text = "Location is ${result.latitude} and ${result.longitude}" // Navigate to map activity to display location val intent = Intent(this, MapActivity::class.java) intent.putExtra("lat", result.latitude) intent.putExtra("long", result.longitude) startActivity(intent) } else { binding.locationUpdate.text = task.exception.toString() } } }
🌐
Medium
alexportillo0519.medium.com › fused-location-provider-in-kotlin-47350c346ef3
Fused Location Provider in Kotlin | by Alexander Portillo | Medium
March 3, 2022 - Fused Location Provider in Kotlin I will be showing you how to use the fused location provider to get the device’s current location. 1. Add the dependency Go to your build.gradle (Module: app) file …
🌐
GeeksforGeeks
geeksforgeeks.org › kotlin › using-fused-location-api-to-fetch-current-location-in-android
Using Fused Location API to Fetch Current Location in Android - GeeksforGeeks
July 23, 2025 - private fun setLocationListner() { val fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this) // for getting the current location update after every 2 seconds with high accuracy val locationRequest = LocationRequest().setInterval(2000).setFastestInterval(2000) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) fusedLocationProviderClient.requestLocationUpdates( locationRequest, object : LocationCallback() { override fun onLocationResult(locationResult: LocationResult) { super.onLocationResult(locationResult) for (location in locationResult.locations) { longPlaceholder.text = location.latitude.toString() latPlaceholder.text = location.longitude.toString() } // Things don't end here // You may also update the location on your web app } }, Looper.gfgLooper() ) }
🌐
Medium
droidbyme.medium.com › get-current-location-using-fusedlocationproviderclient-in-android-cb7ebf5ab88e
Get Current location using FusedLocationProviderClient in Android | by Droid By Me | Medium
January 2, 2019 - private FusedLocationProviderClient mFusedLocationClient;private TextView txtLocation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.txtLocation = (TextView) findViewById(R.id.txtLocation); mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this); }; }
🌐
Esri Developer
developers.arcgis.com › kotlin › sample-code › show-device-location-using-fused-location-data-source
Show device location using fused location data source | ArcGIS Maps SDK for Kotlin | Esri Developer
* */ package com.esri.arcgismaps.sample.showdevicelocationusingfusedlocationdatasource.components import android.app.Application import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.arcgismaps.location.CustomLocationDataSource import com.arcgismaps.location.LocationDisplayAutoPanMode import com.arcgismaps.mapping.ArcGISMap import com.arcgismaps.mapping.BasemapStyle import com.arcgismaps.mapping.view.LocationDisplay import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel import kotlinx.coroutines.launch class ShowDeviceLocationUsi
🌐
GitHub
github.com › rohitchaddha › Get-Current-location-using-FusedLocationProviderClient-in-Android-Kotlin-
GitHub - rohitchaddha/Get-Current-location-using-FusedLocationProviderClient-in-Android-Kotlin-: Demonstrates use of the Google Play services Location API to retrieve the last known location for a device. · GitHub
This sample uses [FusedLocationProviderClient] This sample uses [FusedLocationProviderClient] (https://developer.android.com/reference/com/google/android/gms/location/LocationServices.html). Getting Started This sample uses the Gradle build system. To build this project, use the "gradlew build" command or use "Import Project" in Android Studio.
Author   rohitchaddha
🌐
GitHub
github.com › raviyadav5951 › FusedLocationProviderClient
GitHub - raviyadav5951/FusedLocationProviderClient: FusedLocationProviderClient is new way to fetch the user current location in terms of latitude and longitude. · GitHub
FusedLocationProviderClient is new way to fetch the user current location in terms of latitude and longitude. - raviyadav5951/FusedLocationProviderClient
Starred by 10 users
Forked by 4 users
Languages   Java
🌐
B4X
b4x.com › home › forums › b4a - android › additional libraries, classes and official updates
FusedLocationProviderGMS (Latest) | B4X Programming Forum
December 28, 2023 - This is a new FusedLocationProviderGMS library that is based on the latest version of Google Mobile Services (GMS). Unlike the old version of the FusedLocationProvider library, this version uses the FusedLocationProviderClient class in place of the deprecated FusedLocationProvider class. The...