title: How to use LocationMarnager#getCurrentLocation in Android
body: <p>I need to get current location information. For now I am using <a href="https://developer.android.com/reference/android/location/LocationManager#getLastKnownLocation(java.lang.String)" rel="noreferrer">getLastKnownLocation</a> but sometimes it might return null or obsolete information. I'm trying to use <a href="https://developer.android.com/reference/android/location/LocationManager#requestSingleUpdate(java.lang.String,%20android.app.PendingIntent)" rel="noreferrer">requestSingleUpdate</a> but it deprecated in API level 30 and ask me to use <a href="https://developer.android.com/reference/android/location/LocationManager#getCurrentLocation(java.lang.String,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20java.util.function.Consumer%3Candroid.location.Location%3E)" rel="noreferrer">getCurrentLocation</a> instead. How can i achieve it?</p>
  <p>Here is my current code for reference.</p>
  <pre><code>LocationManager locationManager = (LocationManager) ApplicationProvider.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
  Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
  float accuracy = location.getAccuracy();
  double altitude = location.getAltitude();
  double latitude = location.getLatitude();
  double longitude = location.getLongitude();
  float speed = location.getSpeed();
  </code></pre>