In this Android location manager tutorial, you will learn how to get your current location in Android using GPS. We will use the predefined LocationListener to obtain location information from the device. First we are going to update our location every 2 seconds. Then if our location gets changed, we will update it. We are fetching the latitude and longitude of the current location of an Android device. Also, if you are interested in learning the complete Android Google Maps tutorial, you can refer to it.

Current Location of an Android device
latitude longitude

Permissions for accessing Location:

To run our GPS Location Manager application, we need to provide the permissions given below.

  • ACCESS_FINE_LOCATION: This permission will give the application access to the GPS location coordinates.
  • INTERNET: This permission will allow the application to use the Internet. Add the lines of code below to your Android manifest file.

Snippet1 :

Using the Android Location Manager

Working with the java file

Implement a LocationListener and make a global object for the LocationManager and implement all the unimplemented methods.


We will need to call the method requestLocationUpdates to get the current location as it’s updated by the user.


The parameters of this function are as follows:

provider the name of the provider with which we would like to regiser.
minTime minimum time interval between location updates (in milliseconds).
minDistance minimum distance between location updates (in meters).
listener a LocationListener whose onLocationChanged(Location) method will be called for each location update.

To print the current location if it was changed:

In the onLocationChanged method, we will print the location using a toast. To get the current location we will use the getLatitude() and getLongitude() of a location type variable.

How to get the current location of an Android device.

Use the below code to print the location.


But what if the GPS is not enabled?

We can handle this event in the onProviderDisabled function. We need to redirect our application to the Location settings of the device if the GPS has been disabled.

For that, we will use the code below.


android gps

Listing 1: The complete code for Android’s MainActivity file :

How do I check the GPS Location manager application in an emulator?

  1. Go to Window > Open perspective > DDMS
  2. Choose the emulator you want to work on.
  3. Go to the Emulator Control tab.
  4. Pass the location from the Location Control section.

Screenshot (81)


This tutorial is all about using GPS to get the current location in Android. If you have any suggestions or have any errors while implementing this procedure, feel free to comment below.