🌐
GitHub
github.com › android › location-samples
GitHub - android/location-samples: Multiple samples showing the best practices in location APIs on Android. · GitHub
August 23, 2023 - Multiple samples showing the best practices in location APIs on Android. - android/location-samples
Starred by 2.7K users
Forked by 2.7K users
Languages   Kotlin 87.7% | Java 12.3%
🌐
Google
developers.google.com › google maps platform › android › maps sdk for android › show my location
Show My Location | Maps SDK for Android | Google for Developers
Display an error message // ... } } @Override protected void onResumeFragments() { super.onResumeFragments(); if (permissionDenied) { // Permission was not granted, display error dialog. showMissingPermissionError(); permissionDenied = false; } } /** * Displays a dialog with error message explaining that the location permission is missing. */ private void showMissingPermissionError() { PermissionUtils.PermissionDeniedDialog .newInstance(true).show(getSupportFragmentManager(), "dialog"); } } ... Git is required to run this sample locally. The following command clones the sample application repository. git clone git@github.com:googlemaps-samples/android-samples.git
🌐
Google
developers.google.com › google maps platform › android › maps sdk for android › location data
Location Data | Maps SDK for Android | Google for Developers
Key actions include requesting `ACCESS_COARSE_LOCATION` or `ACCESS_FINE_LOCATION` permissions at runtime, especially in Android 6.0+. The `MyLocationDemoActivity` class handles these requests. The My Location layer, activated by `setMyLocationEnabled(true)`, shows the device's location on a map. Google Play Services Location API is recommended for programmatic location requests, offering features like geofencing and location monitoring. The examples shows how to use Kotlin and Java to implement this functionality.\n"]]
🌐
TutorialsPoint
tutorialspoint.com › android › android_location_based_services.htm
Android - Location Based Services
The LocationRequest object is used to request a quality of service (QoS) for location updates from the LocationClient. There are following useful setter methods which you can use to handle QoS. There are equivalent getter methods available which you can check in Android official documentation. Now for example, if your application wants high accuracy location it should create a location request with setPriority(int) set to PRIORITY_HIGH_ACCURACY and setInterval(long) to 5 seconds.
🌐
GitHub
github.com › treehouse › android-location-example
GitHub - treehouse/android-location-example: Project files for a blog post about the basics of using location in Android via Google Play Services
This is an example project of how to use Location Services from Google Play Services to find a user's current location and display it on a map. It is built on the "Google Map Activity" template from Android Studio and is featured in a Treehouse blog post about location in Android.
Starred by 61 users
Forked by 66 users
Languages   Java 100.0% | Java 100.0%
🌐
Vogella
vogella.com › tutorials › AndroidLocationAPI › article.html
Android Location API with the fused location provider - Tutorial
February 26, 2026 - Create a new project called de.vogella.android.locationapi.simple with the Activity called ShowLocationActivity. This example will not use the Google Map therefore, it also runs on an Android device. Change your layout file from the <filename class="directory">res/layout_ folder to the following code.
🌐
ProTech
protechtraining.com › blog › post › tutorial-android-location-service-example-198
Tutorial: Android Location Service Example - ProTech Training
April 28, 2011 - 5) Getting The User Location In this section: - We want to be able to get user location information such as latitude and longitude. - We do not display yet a marker on the map but we set the center of the map to be the position of the user. Below is the code of the LocationActivity class to get user location on Android.
🌐
DigitalOcean
digitalocean.com › community › tutorials › android-location-api-tracking-gps
Android Location API to track your current location | DigitalOcean
August 3, 2022 - There are two ways to get a users location in our application: android.location.LocationListener : This is a part of the Android API.
🌐
GitHub
github.com › dv-android › android-location-example
GitHub - dv-android/android-location-example
This is an example project of how to use Location Services from Google Play Services to find a user's current location and display it on a map. It is built on the "Google Map Activity" template from Android Studio and is featured in a Treehouse blog post about location in Android.
Author   dv-android
Find elsewhere
🌐
Java Code Geeks
examples.javacodegeeks.com › home › android › core › location
Android Location Based Services Example - Java Code Geeks
December 23, 2013 - Our example shows a use of Location Services in order to get the current location, by choosing the best provider at each time. For this tutorial, we will use the following tools in a Windows 64-bit platform: ... Open Eclipse IDE and go to File → New → Project → Android Application Project.
🌐
Toptal
toptal.com › android › android-developers-guide-to-google-location-services-api
Android Developer’s Guide to the Google Location Services API | Toptal®
January 4, 2023 - An example is the wildly popular application Foursquare, where users who frequent to an establishment and “check in” often win discounts. Uber, which helps you get a ride from your mobile phone at a lower rate than a normal taxi.
🌐
Medium
medium.com › @pavan.kr116 › exploring-location-services-in-android-a-step-by-step-guide-c1c733f470d9
Exploring Location Services in Android: A Step-by-Step Guide | by Pavan namepalli | Medium
September 21, 2023 - In your AndroidManifest.xml file, add the necessary permissions for accessing the device's location. In this example, we use ACCESS_FINE_LOCATION
🌐
Android Developers
developer.android.com › core areas › sensors and location › build location-aware apps
Build location-aware apps | Sensors and location | Android Developers
Location in Android 10 with Kotlin: Learn how to request location on devices that run Android 10, including requesting location while the app is in use.
Top answer
1 of 16
456

I have created a small application with step by step description to get current location's GPS coordinates.

Complete example source code is in Get Current Location coordinates , City name - in Android.


See how it works:

  • All we need to do is add this permission in the manifest file:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
  • And create a LocationManager instance like this:

    LocationManager locationManager = (LocationManager)
    getSystemService(Context.LOCATION_SERVICE);
    
  • Check if GPS is enabled or not.

  • And then implement LocationListener and get coordinates:

    LocationListener locationListener = new MyLocationListener();
    locationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
    
  • Here is the sample code to do so


/*---------- Listener class to get coordinates ------------- */
private class MyLocationListener implements LocationListener {

    @Override
    public void onLocationChanged(Location loc) {
        editLocation.setText("");
        pb.setVisibility(View.INVISIBLE);
        Toast.makeText(
                getBaseContext(),
                "Location changed: Lat: " + loc.getLatitude() + " Lng: "
                    + loc.getLongitude(), Toast.LENGTH_SHORT).show();
        String longitude = "Longitude: " + loc.getLongitude();
        Log.v(TAG, longitude);
        String latitude = "Latitude: " + loc.getLatitude();
        Log.v(TAG, latitude);

        /*------- To get city name from coordinates -------- */
        String cityName = null;
        Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
        List<Address> addresses;
        try {
            addresses = gcd.getFromLocation(loc.getLatitude(),
                    loc.getLongitude(), 1);
            if (addresses.size() > 0) {
                System.out.println(addresses.get(0).getLocality());
                cityName = addresses.get(0).getLocality();
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        String s = longitude + "\n" + latitude + "\n\nMy Current City is: "
            + cityName;
        editLocation.setText(s);
    }

    @Override
    public void onProviderDisabled(String provider) {}

    @Override
    public void onProviderEnabled(String provider) {}

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
}

2 of 16
47

There are already many answers there but I want to show latest way to get location using Google API, so new programmers can use new method:

I have written detailed tutorial on current location in android at my blog demonuts.com You can also find full source code developed with android studio.

First of all, put this in gradle file

 compile 'com.google.android.gms:play-services:9.0.2'

then implement necessary interfaces

public class MainActivity  extends BaseActivitiy implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener

declare instances

  private GoogleApiClient mGoogleApiClient;
  private Location mLocation;
  private LocationManager locationManager;
  private LocationRequest mLocationRequest;

put this in onCreate()

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

At last, override necessary methods

 @Override
    public void onConnected(Bundle bundle) {
        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;
        } startLocationUpdates();
        mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        if(mLocation == null){
            startLocationUpdates();
        }
        if (mLocation != null) {
            double latitude = mLocation.getLatitude();
            double longitude = mLocation.getLongitude();
        } else {
            // Toast.makeText(this, "Location not Detected", Toast.LENGTH_SHORT).show();
        }
    }

    protected void startLocationUpdates() {
        // Create the location request
        mLocationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                .setInterval(UPDATE_INTERVAL)
                .setFastestInterval(FASTEST_INTERVAL);
        // Request location updates
        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;
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
                mLocationRequest, this);
        Log.d("reque", "--->>>>");
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.i(TAG, "Connection Suspended");
        mGoogleApiClient.connect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Log.i(TAG, "Connection failed. Error: " + connectionResult.getErrorCode());
    }

    @Override
    public void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }
    @Override
    public void onLocationChanged(Location location) {

    }

Don't forget to start GPS in your device before running app.

🌐
Android Developers
developer.android.com › api reference › location
Location | 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 · 中文 – 简体
🌐
GeeksforGeeks
geeksforgeeks.org › android › how-to-get-user-location-in-android
How to get user location in Android - GeeksforGeeks
July 15, 2025 - <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> We need to add all these permissions in the AndroidManifest.xml. To access this file, select your project view as Android and click on: app->manifests->AndroidManifest.xml. After adding all the permissions, this is how the AndroidManifest.xml file looks like: XML · <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.getuserlocation"> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:nam
🌐
Android Developers
developer.android.com › core areas › sensors and location › request location updates
Request location updates | Sensors and location | Android Developers
This document explains how to request regular updates about a device's location using the Fused Location Provider's requestLocationUpdates() method in Android.
🌐
Android Developers
stuff.mit.edu › afs › sipb › project › android › docs › training › basics › location › locationmanager.html
Using the Location Manager | Android Developers
For example, a points of interest check-in application would require higher location accuracy than say, a retail store locator where a city level location fix would suffice. The snippet below asks for a provider backed by the GPS. LocationProvider provider = locationManager.getProvider(LocationManager.GPS_PROVIDER); Alternatively, you can provide some input criteria such as accuracy, power requirement, monetary cost, and so on, and let Android decide a closest match location provider.
🌐
Treehouse Blog
blog.teamtreehouse.com › beginners-guide-location-android
The Beginner's Guide to Location in Android | Treehouse Blog
June 8, 2023 - Accessing the current location of an Android device is easier than ever, but it can still be a little tricky, especially for the first time. What follows is a guide on the very basics of retrieving a user’s current location and displaying it with a marker on a map.