Get Current Latitude & Longitude in Android

Jyotishgher Astrology
By -
0

 Get Current Latitude & Longitude in Android Without Google Maps API

Learn how to capture the current GPS location (Latitude & Longitude) in an Android application without using the Google Maps API. In this tutorial, you'll learn how to use Android's built-in LocationManager and the FusedLocationProviderClient (no Maps API key required) to get accurate device coordinates.

Get Current Latitude & Longitude in Android Without Google Maps API


In this Article, you'll learn:

  • Get current latitude and longitude in Android
  • Use GPS without Google Maps API
  • Use LocationManager in Java
  • Use Fused Location Provider (No Maps API Key)
  • Request runtime location permissions
  • Display latitude and longitude on screen
  • Best practices for Android location services

Perfect for Android developers building attendance apps, employee tracking systems, field service apps, delivery apps, and GPS-based applications.

Option 1 (Recommended): Android LocationManager (No Google API)

This uses the phone's built-in GPS and Network providers.

Permissions

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

Java:

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

if (ActivityCompat.checkSelfPermission(this,
        Manifest.permission.ACCESS_FINE_LOCATION)
        != PackageManager.PERMISSION_GRANTED) {

    ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            100);
    return;
}

Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if (location != null) {
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    Log.d("GPS", latitude + "," + longitude);
}

No Google Maps API key required.

Option 2 (Best Accuracy): Fused Location Provider

Uses

implementation 'com.google.android.gms:play-services-location:21.3.0'

This does not require a Google Maps API key.

Many developers confuse Google Maps API with Google Play Services.

You can obtain latitude/longitude without displaying a map.

Example:

FusedLocationProviderClient fusedLocationClient =
        LocationServices.getFusedLocationProviderClient(this);

fusedLocationClient.getLastLocation()
        .addOnSuccessListener(location -> {

            if(location != null){

                double lat = location.getLatitude();
                double lon = location.getLongitude();

            }

        });

Advantages:

  • Better accuracy
  • Faster
  • Lower battery usage
  • No Maps API key

Option 3: GPS Only (Offline)

Use

LocationManager.GPS_PROVIDER

Works completely offline.

Requirements:

  • GPS enabled
  • Open sky

No internet needed.

Option 4: Network Provider

LocationManager.NETWORK_PROVIDER

Uses

  • Wi-Fi
  • Mobile towers

Advantages

  • Fast
  • Works indoors

Disadvantage

  • Less accurate

Option 5: OpenStreetMap (OSMDroid)

If you also need a map (without Google Maps), use:

  • OSMDroid
  • OpenStreetMap

Dependency:

implementation 'org.osmdroid:osmdroid-android:6.1.20'

No Google Maps API key required.

Reverse Geocoding (Lat/Lng → Address)

You can convert latitude and longitude to an address using Android's built-in Geocoder:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());

List<Address> addresses =
        geocoder.getFromLocation(latitude, longitude, 1);

if (!addresses.isEmpty()) {

    Address address = addresses.get(0);

    String locality = address.getLocality();
    String state = address.getAdminArea();
    String country = address.getCountryName();
}

If you need to pick a location on a map

Instead of Google Maps, you can use:

  • OSMDroid + OpenStreetMap (free and open source)
  • MapLibre (open-source map SDK)
  • HERE SDK (free tier available)
  • Mapbox (free tier, API key required)

My recommendation

Since I remember you're developing an Android app in Java using Volley and want to avoid Google Maps costs, I'd recommend:

  • Fused Location Provider for capturing latitude and longitude (no Maps API key required).
  • OSMDroid (OpenStreetMap) if you need to let users select or view locations on a map without Google Maps.

This combination is free, reliable, and commonly used in production apps.

Tags:

Post a Comment

0Comments

Post a Comment (0)