First you need to define a LocationListener to handle location changes.

int LOCATION_REFRESH_TIME = 15000; // 15 seconds to update
int LOCATION_REFRESH_DISTANCE = 500; // 500 meters to update

....

private final LocationListener mLocationListener = new LocationListener() {
    @Override
    public void onLocationChanged(final Location location) {
        //your code here
    }
};

Then get the LocationManager and ask for location updates

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_REFRESH_TIME,
            LOCATION_REFRESH_DISTANCE, mLocationListener);
}

And finally make sure that you have added the permission on the Manifest,

For using only network based location use this one

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

For GPS based location, this one

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Answer from Axxiss on Stack Overflow
🌐
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
Once you have created the Location Services client you can get the last known location of a user's device. When your app is connected to these you can use the fused location provider's getLastLocation() method to retrieve the device location.
🌐
Google
developers.google.com › google maps platform › android › maps sdk for android › select current place and show details on a map
Select Current Place and Show Details on a Map | Maps SDK for Android | Google for Developers
This tutorial gets the current place when the user clicks a Get Place button. It offers the user a list of likely places to choose from, then adds a marker on the map at the location of the selected place. The tutorial provides the code you need to interact with the Places SDK for Android.
🌐
Android Developers
developer.android.com › core areas › sensors and location › request location updates
Request location updates | Sensors and location | Android Developers
The last known location of the device provides a handy base from which to start, ensuring that the app has a known location before starting the periodic location updates. The lesson on Getting the Last Known Location shows you how to get the last known location by calling getLastLocation().
🌐
Android Developers
developer.android.com › api reference › location
Location | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Google Support
support.google.com › android › answer › 3467281
Manage your Android device’s location settings - Android Help
Choose location mode (Android 4.4—8.1) Open your device's Settings app. Tap Security and Location Location. If you don't find "Security and Location," tap Location. ... High accuracy: Use GPS, Wi-Fi, mobile networks, and sensors to get the most accurate location.
🌐
Google
developers.google.com › google maps platform › android › maps sdk for android › location data
Location Data | Maps SDK for Android | Google for Developers
Get Started Contact sales · Home ... · Android applications can be made location-aware using Google Maps Platform and the Google Play services Location API....
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-get-current-location-in-android
How to Get Current Location in Android? - GeeksforGeeks
Refer to the following github repo to get the entire code: Getting-Current-Location-Android
Published   July 23, 2025
🌐
Google Support
support.google.com › accounts › answer › 3467281
Manage your Android device’s location settings - Google Account Help
Choose location mode (Android 4.4—8.1) Open your device's Settings app. Tap Security and Location Location. If you don't find "Security and Location," tap Location. ... High accuracy: Use GPS, Wi-Fi, mobile networks, and sensors to get the most accurate location.
🌐
DigitalOcean
digitalocean.com › community › tutorials › android-location-api-tracking-gps
Android Location API to track your current location | DigitalOcean
August 3, 2022 - Android Location API can be used to track your mobile current location and show in the app. In this tutorial, we’ll develop an application that fetches the user’s current location programmatically. There are two ways to get a users location in our application:
🌐
Javapapers
javapapers.com › android › get-current-location-in-android
Get Current Location in Android - Javapapers
In ‘Location Controls’ panel, ‘Manual’ tab, give the Longitude and Latitude as input and ‘Send’. Find Places Nearby in Google Maps using Google Places API–Android App · Android Get Address with Street Name, City for Location with Geocoding
🌐
Medium
medium.com › @shaikvazid333 › introduction-9c77c2719596
How to Get User Location in Android with Location Services | by Vazid Shaik | Medium
October 18, 2024 - In the code, think of FusedLocationProviderClient as the GPS manager, TextViews as digital signs showing location details, the 'Get Location' Button as the trigger to fetch the user's location, and REQUEST_CODE as a secret code for asking permission. Together, they make your app location-savvy! 🌐✨ · In the onCreate block of the MainActivity in this Android app, the scene is set for the app's debut.
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-get-user-location-in-android
How to get user location in Android - GeeksforGeeks
July 15, 2025 - Once the LocationRequest object is ready, set it on the FusedLocationProviderClient object to get the final location. Let's now look at the MainActivity.java file. ... import android.Manifest; import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.os.Looper; import android.provider.Settings; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; impo
🌐
Medium
sachankapil.medium.com › latest-method-how-to-get-current-location-latitude-and-longitude-in-android-give-support-for-c5132474c864
Latest Method: How to get Current Location (Latitude and Longitude) in Android & Give support for…
January 27, 2023 - Now after learning how can we get a location in android by Location Manager API, we are moving to the second method Fused Location Provider (Google Play Services Location APIs).
🌐
Reddit
reddit.com › r/androiddev › is there any non-complicated way of fetching current location in android
r/androiddev on Reddit: Is there any non-complicated way of fetching current location in Android
May 13, 2024 -

There are quite a lot of branches of code that we would have to manage if we want to fetch location of the user. First check if we have the desired permissions -> if not then get the permissions -> if permission granted then check the settings -> if the settings are not correct, then ask user to switch on the gps -> then finally fetch the location.

In the whole process, a lot of things can happen. And we also have to show the permission rationale at some point. And since we have to do this in most of the applications, is there any easy way of doing all this. I searched on github and found a library for this, but currently I am using compose, and its not easy to use this library in compose, as it relies heavily on activity lifecycle methods.

So my question is: Is there a straighforward way of fetching location in android, which is also not awkward to use along with compose?

🌐
Medium
mrappbuilder.medium.com › how-to-get-current-location-google-map-sdk-in-android-993638d17bd1
How to Get Current Location Google Map SDK in Android | by Anil Kr Mourya | Medium
June 26, 2023 - 4. Get the current location: To get the current location, you can use the Fused Location Provider API provided by Google Play Services.
Top answer
1 of 16
456

I have created a small application with step by step description to get current location's GPS coordinates.

Complete example source code is in Get Current Location coordinates , City name - in Android.


See how it works:

  • All we need to do is add this permission in the manifest file:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
  • And create a LocationManager instance like this:

    LocationManager locationManager = (LocationManager)
    getSystemService(Context.LOCATION_SERVICE);
    
  • Check if GPS is enabled or not.

  • And then implement LocationListener and get coordinates:

    LocationListener locationListener = new MyLocationListener();
    locationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
    
  • Here is the sample code to do so


/*---------- Listener class to get coordinates ------------- */
private class MyLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location loc) {
        editLocation.setText("");
        pb.setVisibility(View.INVISIBLE);
        Toast.makeText(
                getBaseContext(),
                "Location changed: Lat: " + loc.getLatitude() + " Lng: "
                    + loc.getLongitude(), Toast.LENGTH_SHORT).show();
        String longitude = "Longitude: " + loc.getLongitude();
        Log.v(TAG, longitude);
        String latitude = "Latitude: " + loc.getLatitude();
        Log.v(TAG, latitude);

        /*------- To get city name from coordinates -------- */
        String cityName = null;
        Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
        List<Address> addresses;
        try {
            addresses = gcd.getFromLocation(loc.getLatitude(),
                    loc.getLongitude(), 1);
            if (addresses.size() > 0) {
                System.out.println(addresses.get(0).getLocality());
                cityName = addresses.get(0).getLocality();
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        String s = longitude + "\n" + latitude + "\n\nMy Current City is: "
            + cityName;
        editLocation.setText(s);
    }

    @Override
    public void onProviderDisabled(String provider) {}

    @Override
    public void onProviderEnabled(String provider) {}

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
}

2 of 16
47

There are already many answers there but I want to show latest way to get location using Google API, so new programmers can use new method:

I have written detailed tutorial on current location in android at my blog demonuts.com You can also find full source code developed with android studio.

First of all, put this in gradle file

 compile 'com.google.android.gms:play-services:9.0.2'

then implement necessary interfaces

public class MainActivity  extends BaseActivitiy implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener

declare instances

  private GoogleApiClient mGoogleApiClient;
  private Location mLocation;
  private LocationManager locationManager;
  private LocationRequest mLocationRequest;

put this in onCreate()

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

At last, override necessary methods

 @Override
    public void onConnected(Bundle bundle) {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        } startLocationUpdates();
        mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        if(mLocation == null){
            startLocationUpdates();
        }
        if (mLocation != null) {
            double latitude = mLocation.getLatitude();
            double longitude = mLocation.getLongitude();
        } else {
            // Toast.makeText(this, "Location not Detected", Toast.LENGTH_SHORT).show();
        }
    }

    protected void startLocationUpdates() {
        // Create the location request
        mLocationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                .setInterval(UPDATE_INTERVAL)
                .setFastestInterval(FASTEST_INTERVAL);
        // Request location updates
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
                mLocationRequest, this);
        Log.d("reque", "--->>>>");
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.i(TAG, "Connection Suspended");
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.i(TAG, "Connection failed. Error: " + connectionResult.getErrorCode());
    }

    @Override
    public void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }
    @Override
    public void onLocationChanged(Location location) {

    }

Don't forget to start GPS in your device before running app.

🌐
Vogella
vogella.com › tutorials › AndroidLocationAPI › article.html
Android Location API with the fused location provider - Tutorial
February 26, 2026 - If its not enabled you can send the user to the settings via an Intent with the Settings.ACTION_LOCATION_SOURCE_SETTINGS action for the android.provider.Settings class. LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabled = service .isProviderEnabled(LocationManager.GPS_PROVIDER); // check if enabled and if not send user to the GSP settings // Better solution would be to display a dialog and suggesting to // go to the settings if (!enabled) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } Typically you would open an AlarmDialog prompt the user and if he wants to enable GPS or if the application should be canceled.
🌐
Wikihow
wikihow.com › computers and electronics › telephones › smartphones › android › get gps coordinates on android: google maps guide
Get GPS Coordinates on Android: Google Maps Guide
December 11, 2025 - You can check your GPS from your Quick Settings panel by swiping down from the top of your screen, and tapping the cog-and-box icon in top-right. ... Open the Google Maps app on your Android.