You need to use permission first:

Copy<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Next you inside onCreate() method use below code to get access to GPS.

Copy@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            2000, 1, this);

}

Now if GPS is not enabled then you need to refer below code. For detailed explanation, you can refer how to get[DEAD LINK] [current location in android]1 tutorial.

CopyIntent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
         startActivity(intent);

Here we have used intents to redirect user to location settings page so that he can enable the GPS under location settings.

Answer from amit duhan 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 · 中文 – 简体
🌐
Medium
medium.com › pickme-engineering-blog › building-a-modern-android-location-manager-from-legacy-approaches-to-clean-architecture-excellence-3e3e4590533e
Building a Modern Android Location Manager: From Legacy Approaches to Clean Architecture Excellence | by Chamod Lakmal | The PickMe Engineering Blog | Medium
September 16, 2025 - After years of struggling with these pain points in countless projects, I decided to architect a comprehensive solution that addresses these fundamental issues while embracing modern Android development practices. What emerged is a LocationManager that not only simplifies location handling but also provides a blueprint for clean, maintainable, and production ready code.
Top answer
1 of 2
3

You need to use permission first:

Copy<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Next you inside onCreate() method use below code to get access to GPS.

Copy@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            2000, 1, this);

}

Now if GPS is not enabled then you need to refer below code. For detailed explanation, you can refer how to get[DEAD LINK] [current location in android]1 tutorial.

CopyIntent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
         startActivity(intent);

Here we have used intents to redirect user to location settings page so that he can enable the GPS under location settings.

2 of 2
1

you can achieve this easily. you have to write code in main activity. and Main activity implements Locationlistner interface. and overload its four methods. here i'am retrieving my Longitude and Latitide co-ordinates in a textview when application started. and you have to give permission for access location in your manifest file.

as under my code.

Copypackage com.nisarg.gpsdemo;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements LocationListener {

    private LocationManager locationManager;
 private TextView textview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textview=(TextView)findViewById(R.id.textView);

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        Location location = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);

        onLocationChanged(location);
    }

    @Override
    public void onLocationChanged(Location location) {
        double longitude=location.getLongitude();
        double latitude=location.getLatitude();
        textview.setText("Longitude:   "+longitude+"   Latitide:  "+latitude);

    }

    @Override
    public void onStatusChanged(String s, int i, Bundle bundle) {

    }

    @Override
    public void onProviderEnabled(String s) {

    }

    @Override
    public void onProviderDisabled(String s) {

    }
}

and you have to give permission like this in manifest file.

Copy <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

And last warning. you have to give permission to your application and start mobile data and GPS before you open application. either it will be crashed.

that's it. hope it will help you. :)

🌐
Android Developers
stuff.mit.edu › afs › sipb › project › android › docs › training › basics › location › locationmanager.html
Using the Location Manager | Android Developers
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" /> LocationManager is the main class through which your application can access location services on Android. Similar to other system services, a reference ...
🌐
Vanderbilt
dre.vanderbilt.edu › ~schmidt › android › android-4.0 › out › target › common › docs › doc-comment-check › reference › android › location › LocationManager.html
LocationManager | Android Developers
Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.
Find elsewhere
🌐
Reddit
reddit.com › r/androiddev › fusedlocationproviderclient vs locationmanager - what to use? possible deprecation?
r/androiddev on Reddit: FusedLocationProviderClient vs LocationManager - What to use? Possible deprecation?
May 2, 2023 -

We are currently working on an App that does a lot with users' locations. Therefore we are evaluating FusedLocationProviderClient and the "old" LocationManager to access the user's location over a long period of time.

The accuracy of the location is extremely important and we want to get the maximum out of the device. Initial testing showed great results with the "new" fused location provider. However, on some devices, this client is not available and in very rare cases the locations get really inaccurate after some time (<10min).

For some devices/cases we are thinking of using the "old" LocationManager, but my question is if this LocationManager will stick around in the future. I did some research but I wasn't able to find a lot of details. Google just "highly recommends switching to FusedLocationProviderClient", but it's missing some features of the LocationManager such as providing GNSS information.

Is it a good idea to use LocationManager and all the information that it provides such as GNSS Info?

Maybe some of you also did some research on this topic and can share the results.

🌐
Google Groups
groups.google.com › g › codenameone-discussions › c › KomuO0JkCYY
Android LocationManager Implementation .. coarse provider?
On a native Android app I would start a series of location listeners. One would listen for a fast but inaccurate (1km) location (cell tower/WiFi), then as time progresses I would use the slower but more accurate(10m) location data for something else. Codename One's iPhone LocationManager seems to do this, but the Android implementation seems to only use the GPS provider.
🌐
Medium
medium.com › @huseyin_37353 › best-way-to-get-location-on-android-72695fef17a4
Best and Trustworthy Way to Get Location on Android | by Hüseyin Bülbül | Medium
October 16, 2020 - private fun prepareAndStartCoreLocation(){ deviceManager = getSystemService(Context.LOCATION_SERVICE) as android.location.LocationManager deviceListener = object: LocationListener { override fun onLocationChanged(location: Location?) { stopCoreLocation() location?.let { haveNewLocation(it) } } override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?)
🌐
Reddit
reddit.com › r/androiddev › how does locationmanager.network_provider internally work?
r/androiddev on Reddit: How does LocationManager.NETWORK_PROVIDER internally work?
July 12, 2023 -

According to the documentation

This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup.

It's pretty sweet how you can extract location out of devices even if they don't have (or disabled) GPS, but how does this API extract location from cell towers or wi fi? I guess essentially instead of extracting the extact device's lat and long, it extract's the location of whatever router (in case of wifi) or the closest cell tower that the cellular service provider can reach.

I didn't even know cell towers and wifi gave away latitude/longitude data like that so plainly.

🌐
Android Developers
developer.android.com › sdk › api_diff › 30 › changes › android.location.LocationManager
android.location.LocationManager
JDiff is a Javadoc doclet which generates an HTML report of all the packages, classes, constructors, methods, and fields which have been removed, added or changed in any way, including their documentation, when two APIs are compared.
🌐
Medium
medium.com › @boobalaninfo › accessing-users-location-guide-android-2023-60a6f018a718
Accessing User’s Location Guide Android 2023 | by Boobalan Munusamy | Medium
June 22, 2023 - The Location Manager is a class ... location services. It allows you to request location updates from different providers, such as GPS, network, and passive (location updates from other applications)....
🌐
HERE Technologies
here.com › docs › bundle › sdk-for-android-developer-guide › page › topics › positioning.html
HERE Technologies Documentation | HERE Docs
Skip to main contentSkip to search · Powered by Zoomin Software. For more details please contactZoomin · ©2026 HERE · Contact usCookie PreferencesResponsible AITermsSecurityPrivacyPrivacy CharterModern Slavery StatementDo Not Sell My Personal Information · Other Sites · here.comHERE ...
🌐
PCC
spot.pcc.edu › ~mgoodman › developer.android.com › guide › topics › location › strategies.html
Location Strategies | Android Developers
Getting user location in Android works by means of callback. You indicate that you'd like to receive location updates from the LocationManager ("Location Manager") by calling requestLocationUpdates(), passing it a LocationListener.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › locationmanager
Newest 'locationmanager' Questions - Stack Overflow
The LocationManager class in Android SDK provides access to the system location services.
🌐
Tealium
docs.tealium.com › platforms › android-kotlin › api › location-manager
LocationManager | API Reference | Tealium Docs
September 5, 2025 - The LocationManager class provides methods for gathering location data, creating and monitoring geofences. The following summarizes the commonly used methods of the LocationManager class for Tealium Kotlin.
🌐
DigitalOcean
digitalocean.com › community › tutorials › android-location-api-tracking-gps
Android Location API to track your current location | DigitalOcean
August 3, 2022 - The android.location has two means of acquiring location data: LocationManager.GPS_PROVIDER: Determines location using satellites.
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-get-current-location-in-android
How to Get Current Location in Android? - GeeksforGeeks
In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request the user’s permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file.
Published   July 23, 2025
🌐
Android Developers
stuff.mit.edu › afs › sipb › project › android › docs › reference › android › location › LocationManager.html
LocationManager - Android SDK | Android Developers
LocationManager · LocationProvider · fullscreen Use Tree NavigationUse Panel Navigation · Summary: Constants | Methods | Inherited Methods | [Expand All] Added in API level 1 · public class · extends Object · This class provides access to the system location services.