I've solved. Here is the code.

locationManager.getCurrentLocation(
    LocationManager.GPS_PROVIDER,
    null,
    application.getMainExecutor(),
    new Consumer<Location>() {
  @Override
  public void accept(Location location) {
    // code
  }
});
Answer from LaoDa581 on Stack Overflow
🌐
Android Developers
developer.android.com › api reference › locationmanager
LocationManager | 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 · 中文 – 简体
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › android.locations.locationmanager.getcurrentlocation
LocationManager.GetCurrentLocation Method (Android.Locations) | Microsoft Learn
[<Android.Runtime.Register("getCurrentLocation", "(Ljava/lang/String;Landroid/location/LocationRequest;Landroid/os/CancellationSignal;Ljava/util/concurrent/Executor;Ljava/util/function/Consumer;)V", "GetGetCurrentLocation_Ljava_lang_String_Landroid_location_LocationRequest_Landroid_os_CancellationSignal_Ljava_util_concurrent_Executor_Ljava_util_function_Consumer_Handler", ApiSince=31)>] abstract member GetCurrentLocation : string * Android.Locations.LocationRequest * Android.OS.CancellationSignal * Java.Util.Concurrent.IExecutor * Java.Util.Functions.IConsumer -> unit override this.GetCurrentLocation : string * Android.Locations.LocationRequest * Android.OS.CancellationSignal * Java.Util.Concurrent.IExecutor * Java.Util.Functions.IConsumer -> unit
🌐
Narkive
android-beginners.narkive.com › EcLapsW3 › locationmanager-getcurrentlocation
LocationManager.getCurrentLocation
Please take a look at the documentation for LocationManager,http://code.google.com/android/reference/android/location/LocationMan... . Cheers, Justin · Post by Friso Kluit Hi, I just installed the beta 0.9 this morning and facing some trouble with the GPS service. The below code fragment worked in m5, but the getCurrentProvider property is not available in beta 0.9 anymore. What is the new way of getting current location? Cheers, Friso this.myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); LocationProvider provider = this.myLocationManager.getProvider("gps"); th
🌐
Java2s
java2s.com › example › android › hardware › get-current-location-from-locationmanager.html
get Current Location from LocationManager - Android Hardware
//package com.java2s; import android.content.Context; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; public class Main { public static final Location getCurrentLocation(Context context) { try {// ww w .
🌐
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 - <uses-permission android:name=... location. locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this);...
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-get-current-location-in-android
How to Get Current Location in Android? - GeeksforGeeks
package org.geeksforgeeks.demo; import android.Manifest; import android.content.pm.PackageManager; import android.location.Location; import android.os.Bundle; import android.widget.Button; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationServices; import com.google.android.gms.tasks.OnSuccessListener; public class MainActivity extends AppCompatActivity { // Declare variable
Published   July 23, 2025
🌐
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 - val hasGps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)//------------------------------------------------------//val hasNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) Step 3: Create an instance of LocationListener (package: android.location) for both(GPS and Network).
Find elsewhere
🌐
Medium
medium.com › @priyavrat.acharya01 › using-new-on-demand-location-update-api-introduced-in-android-11-69c65b3787aa
Using new on demand location update API introduced in Android 11.
September 22, 2020 - // CancelationRequest object can be passed as null. locationManager.getCurrentLocation(LocationManager.NETWORK_PROVIDER, null, this.mainExecutor, locationCallback) } else { // Keep using the legacy code, such as LocationManager.requestSingleUpdate() } } } private val locationCallback = Consumer<Location> { location -> if (null != location) { latTextView.text = "Latitude: " + location.latitude lngTextView.text = "Longitude: " + location.longitude.toString() } } }
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
Javapapers
javapapers.com › android › get-current-location-in-android
Get Current Location in Android - Javapapers
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); LocationListener will be notified based on the distance interval specified or the number seconds. This example provides current location update using GPS provider. Entire Android app code is as follows,
🌐
GitHub
github.com › TommyR22 › Android-getcurrentlocation
GitHub - TommyR22/Android-getcurrentlocation: Example to get current location in Android with google maps api v2 and GPS
meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="INSERT HERE YOUR API KEY" ###in Activity The refresh time: protected void onResume() { super.onResume(); locationManager.requestLocationUpdates(provider, 1000, 1, this); } Copyright (c) 2013 Tommaso Ruscica
Starred by 3 users
Forked by 5 users
Languages   Java 100.0% | Java 100.0%
🌐
GitHub
github.com › TommyR22 › Android-getcurrentlocation › blob › master › README.md
Android-getcurrentlocation/README.md at master · TommyR22/Android-getcurrentlocation
meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="INSERT HERE YOUR API KEY" ###in Activity The refresh time: protected void onResume() { super.onResume(); locationManager.requestLocationUpdates(provider, 1000, 1, this); } Copyright (c) 2013 Tommaso Ruscica
Author   TommyR22
🌐
Stack Overflow
stackoverflow.com › questions › 37878279 › android-current-location
Android- Current location - Stack Overflow
public LatLng getCurrentLocation() { LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = service.getBestProvider(criteria, false); Location location = service.getLastKnownLocation(provider); LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude()); //Log.e("Location",userLocation....
🌐
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
Learn how to use Google Play services location APIs, specifically the Fused Location Provider, to request the last known location of an Android device, which often represents the user's current location.
🌐
Medium
velmurugan-murugesan.medium.com › how-to-get-current-latitude-and-longitude-in-android-example-35437a51052a
How to get current latitude and longitude in android example | by Velmurugan Murugesan | Medium
January 28, 2022 - This Android tutorial is to help learn How to get current latitude and longitude in the Android platform. Knowing the current location in…
🌐
Android Developers
stuff.mit.edu › afs › sipb › project › android › docs › training › basics › location › currentlocation.html
Obtaining the Current Location | Android Developers
In this case, // we're sending the update to a handler which then updates the UI with the new // location. Message.obtain(mHandler, UPDATE_LATLNG, location.getLatitude() + ", " + location.getLongitude()).sendToTarget(); ... } ... }; mLocationManager.requestLocationUpdates(LocationManager.G...
🌐
GitHub
gist.github.com › yudikarma › fff2ea8aa0e6c2946f56b8e44c6f610b
how to get current location android gps and network provider · GitHub
how to get current location android gps and network provider - get location android GPS and Network Provider
🌐
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>