How to Get Current Location in Android Using Location Manager

In this GPS tutorial you will learn how to get current location in android.

LocationManager class provides the facility to get latitude and longitude coordinates of current location. The class in which you want to get location should implement LocationListener and override all its abstract methods.

How to Get Current Location in Android Using Location Manager

Add following permissions to AndroidManifest.xml file.

Following lines of code helps in getting current location.

In requestLocationUpdates() method the 2nd argument is time in milliseconds and 3rd argument is distance in meters. Here I have used 5000 and 5 that means after every 5 seconds and 5 meter the current location is fetched.

To get coordinates use getLatitude() and getLongitude() method on variable of Location class.

Whenever location is changed it can be fetched inside onLocationChanged() method.

Below is simple application that fetches current location on button click and displays it in textview.

Full Source Code




How to Get Current Location in Android Using Location Manager

Comment below if found anything incorrect or have doubts related to above android gps tutorial to get current location.


12 thoughts on “How to Get Current Location in Android Using Location Manager

  1. Shama Furhana

    I’m studying 2nd yr cs engineering . will yu plz give some idea to do mini project in c,c++…..

  2. Vinay A

    When i click the buton it show nothing lang and lat…but i add Toast between this,
    Toast.makeText(getApplicationContext(), “Your Location”, Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(), “Your Location showing”, Toast.LENGTH_LONG).show();

    But,Am able to find long and lat.
    Advance Thanks

    1. Admin Post author

      Makes sure the gps is one, test it in real android device.

  3. Todd

    Hello Neeraj!

    I am running the tutorial code on a real device and gps is on but onLocationChanged is never called. I was wondering what version of the sdk you are running?


  4. avinash

    this code is properly work.nycccc and easy code for get loacation.thank you

  5. vineeth

    your code is not working
    just button is getting displayed
    when i clicked on that button,nothing got displayed


    how to get current location not like above.. means current location place name should be displayed


Leave a Reply

Your email address will not be published. Required fields are marked *