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
🌐
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
Find the CurrentPlaceDetailsOnMap project at this location: PATH-TO-SAVED-REPO/android-samples/tutorials/java/CurrentPlaceDetailsOnMap (Java) or PATH-TO-SAVED-REPO/android-samples/tutorials/kotlin/CurrentPlaceDetailsOnMap (Kotlin)
🌐
Medium
medium.com › @grudransh1 › best-way-to-get-users-location-in-android-app-using-location-listener-from-java-in-android-studio-77882f8b87fd
Best way to get user’s location in android app using Location Listener from JAVA in android studio | by Rudransh Gupta | Medium
May 17, 2020 - Hence, the best way I found to get user’s current latitude and longitude is Location Listener and get Location updates if the above method return null location. In your activity.java file you have to implement LocationListener method in seperate class and get updates as you click the button and then do the remaining taks.
Top answer
1 of 4
2

I have written detailed tutorial covering this topic here on demonuts.com.You can find more description here and also you can download whole demo source code for better understanding.

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.

2 of 4
1

You need to define LocationListener .

public class MainActivity extends Activity implements LocationListener{
    protected LocationManager locationManager;
    protected LocationListener locationListener;
    protected Context context;
    TextView txtLat;
    String lat;
    String provider;
    protected String latitude,longitude; 
    protected boolean gps_enabled,network_enabled;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txtLat = (TextView) findViewById(R.id.textview1);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }
    @Override
    public void onLocationChanged(Location location) {
        txtLat = (TextView) findViewById(R.id.textview1);
        txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.d("Latitude","disable");
    }

    @Override
    public void onProviderEnabled(String provider) {
        Log.d("Latitude","enable");
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        Log.d("Latitude","status");
    }
}

And need to give below permission :

ACCESS_COARSE_LOCATION : It is used when we use network location provider for our Android app.

ACCESS_FINE_LOCATION : It is providing permission for both providers.

INTERNET : permission is must for the use of network provider.

🌐
GitHub
github.com › Pritish-git › get-Current-Location › blob › main › MainActivity.java
get-Current-Location/MainActivity.java at main · Pritish-git/get-Current-Location
import com.google.android.gms.location.LocationCallback; · import com.google.android.gms.location.LocationRequest; · import com.google.android.gms.location.LocationResult; · import com.google.android.gms.location.LocationServices; · ...
Author   Pritish-git
🌐
YouTube
youtube.com › learn with deeksha
How to Get Current Location On Google Map in Android Studio| Java| Android Studio Tutorial - YouTube
In this video, you will learn how to get the user's current location on Google Map in Android Studio.I forgot to explain the location request code. Find the ...
Published   January 26, 2022
Views   19K
🌐
W3Docs
w3docs.com › java
How to get current location in Android
import android.location.Location; import android.location.LocationManager; public class MainActivity extends AppCompatActivity { private LocationManager locationManager; private Location currentLocation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); } @Override protected void onResume() { super.onResume(); requestLocationUpdates(); } @Override protected void onPause() { super.onPause(); removeLocationUpdates(); } private void reque
🌐
TutorialsPoint
tutorialspoint.com › how-to-get-current-location-latitude-and-longitude-in-android
How to get current location latitude and longitude in Android?
August 30, 2019 - <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" tools:context=".MainActivity"> <TextView android:id="@+id/showLocation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="Location" android:textSize="24sp" /> <Button android:id="@+id/btnGetLocation" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Get Location" /> </LinearLayout> Step 3 − Add the following code to src/MainActivity.java
Find elsewhere
🌐
Javapapers
javapapers.com › android › get-current-location-in-android
Get Current Location in Android - Javapapers
i am new to android ,i tried the same but when i run it shows me “unfortunately app has stopped working” please help me fix this. ... Very helpful! ... Very nice tutorial.Please tell me how can we use these coordinates to locate this position in the map .thank you ... First you need to display the map fragment (https://javapapers.com/android/show-map-in-android/), then you need to tile these coordinates on top of it by using location service / activity.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-get-current-location-in-android
How to Get Current Location in Android? - GeeksforGeeks
There are two ways to get the current location of any Android device: ... Question: Which one is efficient and why? Answer: Fused Location Provider because it optimizes the device’s use of battery power. Before moving any of the above methods we will have to take location permission. To create a new project in the Android Studio, please refer to How to Create/Start a New Project in Android Studio?
Published   April 7, 2025
🌐
YouTube
youtube.com › watch
Show Current Location on Google Map in Android Studio using Java | Part 2 - YouTube
Welcome to Android Knowledge!In this video, I have share how to show current location on google maps. It will access users current gps and accordingly will s...
Published   January 18, 2023
🌐
DigitalOcean
digitalocean.com › community › tutorials › android-location-api-tracking-gps
Android Location API to track your current location | DigitalOcean
August 3, 2022 - requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) method of the LocationManager class is used to register the current activity to be notified periodically by the named provider. onLocationChanged is invoked periodically based upon the minTime and minDistance, whichever comes first. Location class hosts the latitude and longitude. To get the current location the following code snippet is used.
🌐
Google
codelabs.developers.google.com › codelabs › while-in-use-location
Receive location updates in Android with Kotlin | Google Codelabs
March 27, 2026 - This method requires such a block ... user taps the button. If you wish to see it, have a look at the MainActivity.kt class. Run your app from Android Studio and try the location button....
🌐
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
developers.google.com › google maps platform › android › maps sdk for android › location data
Location Data | Maps SDK for Android | Google for Developers
Key actions include requesting `ACCESS_COARSE_LOCATION` or `ACCESS_FINE_LOCATION` permissions at runtime, especially in Android 6.0+. The `MyLocationDemoActivity` class handles these requests. The My Location layer, activated by `setMyLocationEnabled(true)`, shows the device's location on a map. Google Play Services Location API is recommended for programmatic location requests, offering features like geofencing and location monitoring. The examples shows how to use Kotlin and Java to implement this functionality.\n"]]
🌐
Stack Overflow
stackoverflow.com › questions › 64951824 › how-to-get-current-location-with-android-studio
position - how to get current Location with android studio - Stack Overflow
try { Geocoder geo = new Geocoder(this.getApplicationContext(), Locale.getDefault()); List<Address> addresses = geo.getFromLocation(currentLocation.getCoordinates().latitude, currentLocation.getCoordinates().longitude, 1); if (addresses.isEmpty()) { autocompleteFragmentFrom.setText(R.string.waiting_for_location); } else { addresses.size(); if (addresses.get(0).getThoroughfare() == null) { pickupLocation.setName(addresses.get(0).getLocality()); } else if (addresses.get(0).getLocality() == null) { pickupLocation.setName("unknown address"); } else { pickupLocation.setName(addresses.get(0).getLoca
🌐
Wordpress
simpledevcode.wordpress.com › 2016 › 09 › 26 › how-to-obtain-current-location-with-android-java
How to obtain current location with Android (Java) – Bits and Pieces of Code
September 27, 2016 - Suppose in your app you would like to obtain the current location of the device. In other words, obtaining stuff like latitude, longitude, and city. Its very simple to do so with Android. ... import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; ... LocationManager localizer = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = localizer.getProviders(true); Location bestPosition = null; //poll for the best, most accurate location for(String s:providers) { Location temp = localizer.getLastKnownLocation(s); if(temp == null) { continue; } if(bestPosition == null || temp.getAccuracy() < bestPosition.getAccuracy()) { bestPosition = temp; } } //get the lat/long double latitude = bestPosition.getLatitude(); double longitude = bestPosition.getLongitude();
🌐
The Crazy Programmer
thecrazyprogrammer.com › home › how to get current location in android using location manager
How to Get Current Location in Android Using Location Manager
January 11, 2017 - LocationManager class provides the facility to get latitude and longitude coordinates of current location. The class in which you want to get location should implement LocationListener and override all its abstract methods.
🌐
Quora
quora.com › How-do-I-find-the-users-current-location-in-Android-Studio
How to find the user's current location in Android Studio - Quora
Answer (1 of 3): got a nice tutorial here which is using fused location provider api http://www.askfortricks.com/2016/03/get-location-in-android-using-fusedlocationprovider-api-or-make-android-app-location-aware/