So here's how you can get your current location. I am skipping the permission part as you can do that yourself.

private fun isLocationEnabled(): Boolean {
        val locationManager: LocationManager =
            getSystemService(Context.LOCATION_SERVICE) as LocationManager
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(
            LocationManager.NETWORK_PROVIDER
        )
    }
 private fun getLastLocation() {
        if (isLocationEnabled()) {
           fusedLocationClient.lastLocation.addOnCompleteListener(this) { task ->
                val location: Location? = task.result
                if (location != null) {
                    //use the location latitude and logitude as per your use.
                    val latitude = location.latitude
                    val longitude = location.longitude
                }
            }
        }
Answer from Jayanta Sarkar on Stack Overflow
Top answer
1 of 3
1

So here's how you can get your current location. I am skipping the permission part as you can do that yourself.

private fun isLocationEnabled(): Boolean {
        val locationManager: LocationManager =
            getSystemService(Context.LOCATION_SERVICE) as LocationManager
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(
            LocationManager.NETWORK_PROVIDER
        )
    }
 private fun getLastLocation() {
        if (isLocationEnabled()) {
           fusedLocationClient.lastLocation.addOnCompleteListener(this) { task ->
                val location: Location? = task.result
                if (location != null) {
                    //use the location latitude and logitude as per your use.
                    val latitude = location.latitude
                    val longitude = location.longitude
                }
            }
        }
2 of 3
0

you need to request location updates try the following for instance


    val fusedLocationProviderClient =
        LocationServices.getFusedLocationProviderClient(activity)
    val locationCallback = object : LocationCallback() {
        override fun onLocationResult(locationResult: LocationResult) {
            val location = locationResult.lastLocation
            if (location != null) {
                val latitude = location.latitude
                val longitude = location.longitude

                // Use latitude and longitude for your purposes
                Log.d("Location", "Latitude: $latitude, Longitude: $longitude")

                // Remove location updates after receiving one
                fusedLocationProviderClient.removeLocationUpdates(this)
            } else {
                Log.w("Location", "Failed to get location update")
            }
        }
    }

    if (ContextCompat.checkSelfPermission(
            activity,
            Manifest.permission.ACCESS_FINE_LOCATION
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        // Request permissions if not granted
        val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
        activity.requestPermissions(permissions, LOCATION_PERMISSION_CODE)
        return
    }

    val locationRequest =
        LocationRequest.Builder(0L).setPriority(Priority.PRIORITY_HIGH_ACCURACY).build()

    fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, null)
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-get-the-current-gps-location-programmatically-on-android-using-kotlin
How to get the current GPS location programmatically on Android using Kotlin?
November 28, 2020 - import android.Manifest import android.content.Context import android.content.pm.PackageManager import android.location.Location import android.location.LocationListener import android.location.LocationManager import android.os.Bundle import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity(), LocationListener { private lateinit var locationManager: LocationManager private lateinit var tvGpsLocat
๐ŸŒ
theSimplyCoder
thesimplycoder.com โ€บ home โ€บ getting current location on android using kotlin
Getting Current Location on Android Using Kotlin - theSimplyCoder
July 14, 2020 - On Kotlin, you access the location data using the lastLocation provided by FusedLocationProviderClient and it will return the location data such as latitude, longitude, provider, etc. using the fused location provider requires you to grant the ...
Top answer
1 of 2
6

in kotlin any method of the form getX can be written as just x, this is called "property access syntax". There is no separate kotlin version. fusedLocationClient.lastLocation is really exactly the same as fusedLocationClient.getLastLocation(). You can even write this last form in kotlin if you want.

However, this is only true for "get" methods without parameters. The thing is, getCurrentLocation does have parameters so property access syntax is not possible in this case. as you can see here this is the signature of this method:

public Task<Location> getCurrentLocation (int priority, CancellationToken token)

So you should use it like that. for example

fusedLocationClient.getCurrentLocation(LocationRequest.PRIORITY_HIGH_ACCURACY, null)

EDIT:

apparently null as parameter is not allowed. According to https://stackoverflow.com/a/72159436/1514861 this is a possibility:

fusedLocationClient.getCurrentLocation(LocationRequest.PRIORITY_HIGH_ACCURACY, object : CancellationToken() {
            override fun onCanceledRequested(p0: OnTokenCanceledListener) = CancellationTokenSource().token

            override fun isCancellationRequested() = false
        })
        .addOnSuccessListener { location: Location? ->
            if (location == null)
                Toast.makeText(this, "Cannot get location.", Toast.LENGTH_SHORT).show()
            else {
                val lat = location.latitude
                val lon = location.longitude
            }

        }
2 of 2
1
fusedLocationClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, object : CancellationToken() {
        override fun onCanceledRequested(listener: OnTokenCanceledListener) = CancellationTokenSource().token

        override fun isCancellationRequested() = false
    })
    .addOnSuccessListener {
        if (it == null)
            Toast.makeText(this, "Cannot get location.", Toast.LENGTH_SHORT).show()
        else {
            val lat = it.latitude
            val lon = it.longitude
        }

    }
๐ŸŒ
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)
๐ŸŒ
Techpass Master
techpassmaster.com โ€บ learn, practice, implement โ€บ get current location in android studio using kotlin
Get Current Location in Android Studio using Kotlin - Techpass Master
January 13, 2025 - First, you have to need to create a project to get your current location, below are the steps you can follow step by step. Start a new Android Studio Project. Select Empty Activity and click Next.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to get current location in android studio using kotlin | Current location latitude and longitude - YouTube
In this video we are going to learn how to fetch current location of user in android studioIf you have any questions or queries comment down belowSubscribe t...
Published ย  January 17, 2022
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ coding adventure
Get current location in Android Studio | Kotlin - YouTube
Hello there, In this tutorial we will learn how to get current location in android device using FusedLocationProvider...After this video you will be able to ...
Published ย  March 4, 2021
Views ย  19K
๐ŸŒ
Google
codelabs.developers.google.com โ€บ codelabs โ€บ while-in-use-location
Receive location updates in Android with Kotlin | Google Codelabs
March 27, 2026 - Add support to the app for Android 10 and 11 by adding logic to access location in the foreground location or while in use. ... To get you started as quickly as possible, you can build on this starter project.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 65812102 โ€บ kotlin-how-to-get-current-location
android - Kotlin: How to get current location? - Stack Overflow
val locationManager = (context?.getSystemService(LOCATION_SERVICE) as? LocationManager) ?: error("Could not get LocationManager")
๐ŸŒ
Medium
medium.com โ€บ @hasperong โ€บ get-current-location-with-latitude-and-longtitude-using-kotlin-2ef6c94c7b76
Get current location with latitude and longtitude using kotlin | by Hasper Ong | Medium
January 28, 2022 - Get current location with latitude and longtitude using kotlin This tutorial about get current location with latitude and longtitude using kotlin. 2. Add permission in manifest
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ android โ€บ how-to-get-current-location-in-android
How to Get Current Location in Android? - GeeksforGeeks
In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request the userโ€™s permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file.
Published ย  July 23, 2025
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-track-the-current-location-latitude-and-longitude-in-an-android-device-using-kotlin
How to track the current location (Latitude and Longitude) in an android device using Kotlin?\\n
April 20, 2020 - This example demonstrates how to track the current location (Latitude and Longitude) in an android device using Kotlin. Step 1 โˆ’ Create a new project in Android Studio, go to File โ‡’New Project and fill al
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.

Top answer
1 of 2
5

Try as follow

Step 1. Put on your AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com....">

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

    <application ... />

</manifest>

Step 2. Put it above your location request

import android.Manifest
import android.content.pm.PackageManager
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat

...

fun getLocation() {

    ...

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                this,
                arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
                PERMISSION_REQUEST_ACCESS_FINE_LOCATION)
        return
    }
    locationManager!!.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f, locationListener)
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    if (requestCode == PERMISSION_REQUEST_ACCESS_FINE_LOCATION) {
        when (grantResults[0]) {
            PackageManager.PERMISSION_GRANTED -> getLocation()
            PackageManager.PERMISSION_DENIED -> //Tell to user the need of grant permission
        }
    }
}

companion object {
    private const val PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 100
}
2 of 2
1

The LocationManager will throw a SecurityException if the location permission has not been granted.

Information on adding the location permissions to your app can be found here.

๐ŸŒ
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
The accuracy of the location returned is based on the location permissions you've requested and the location sensors that are currently active for the device. To run this sample, location must be enabled. This sample uses [FusedLocationProviderClient] This sample uses [FusedLocationProviderClient] (https://developer.android.com/reference/com/google/android/gms/location/LocationServices.html).
Author ย  rohitchaddha
๐ŸŒ
Javapapers
javapapers.com โ€บ android โ€บ get-current-location-in-android
Get Current Location in Android - Javapapers
To access current location information through location providers, we need to set permissions with android manifest file.