0

I am trying to get the current device location. All I find is how to get last known location - and for that, I have to first open an app that used location service such as Google Maps. But what if I want to be the one to get the current location first, without having to open some other GPS-using app?

  • 2
    Possible duplicate of [What is the simplest and most robust way to get the user's current location on Android?](https://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-on-a) – leonardkraemer Nov 14 '18 at 12:19
  • 1
    Duplicate: https://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android – Harish Jose Nov 14 '18 at 12:20
  • Look for the answers with FusedLocationProvider for the new API – leonardkraemer Nov 14 '18 at 12:21

2 Answers2

0

You need to request location updates. Like mFusedLocationClient.requestLocationUpdates(getLocationRequest(), mLocationCallback, null); And you will get current location inside your mLocationCallback. You can look here https://developer.android.com/training/location/receive-location-updates#updates

Vadim Eksler
  • 865
  • 9
  • 24
0

You need to define a LocationListener to handle changes in location. This link might be of some help How to get current location in Android

shubham
  • 11
  • 4