LocationRequest locationRequest = 
 new LocationRequest.Builder(
  LocationRequest.PRIORITY_HIGH_ACCURACY,
  10000
 ).build();

locationRequest.setFastestInterval(5000);
Answer from Christoph Dahlen on Stack Overflow
🌐
Google
developers.google.com › google play services › locationrequest
LocationRequest | Google Play services | Google for Developers
October 31, 2024 - LocationRequest is used to define parameters for requesting location updates via FusedLocationProviderClient.
🌐
Android Developers
developer.android.com › api reference › locationrequest
LocationRequest | 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 · 中文 – 简体
🌐
Android Developers
developer.android.com › core areas › sensors and location › request location updates
Request location updates | Sensors and location | Android Developers
June 2, 2023 - This document explains how to request regular updates about a device's location using the Fused Location Provider's requestLocationUpdates() method in Android.
Top answer
1 of 1
1

I haven't used location services in a long, long time, so I'm just looking at the documentation for 'LocationRequest.Builder` and guessing at your equivalent code because it looks self-explanatory. Builders are a common pattern, used more often in Java-based APIs like this one than they are used in pure-Kotlin APIs. You can look up "java builder pattern" to read about it.

private fun NewLocation() { 
    val locationRequest = LocationRequest.Builder()
        .setPriority(Priority.PRIORITY_HIGH_ACCURACY)
        .setIntervalMillis(0L)
        .setMinUpdateIntervalMillis(0L)
        .setMaxUpdates(1)
        .build()
    mfusedlocation = LocationServices.getFusedLocationProviderClient(this)
    mfusedlocation.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper())
}

FYI since you're working on a portfolio:

  • Function names in Kotlin start with a verb and lower-case letter by convention. Or if it returns a modified copy of an object, you can use a past participle instead of a phrase starting with a verb. For example, I would rename NewLocation() to something like beginLocationRequest().

  • The mSomething pattern of naming variables (putting abbreviations in front of variable names) is called Hungarian notation. m stands for "member", but Kotlin properties are not even called member variables. I've never seen Hungarian notation used in Kotlin before, and it is rarely used in Java. It is widely regarded as making code less readable, especially with modern IDEs. I would advise against using it in a portfolio project as it is more likely to damage the impression you want to give than it is to help, especially if you are using it inconsistently.

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › android.locations.locationrequest
LocationRequest Class (Android.Locations) | Microsoft Learn
[<Android.Runtime.Register("android/location/LocationRequest", ApiSince=31, DoNotGenerateAcw=true)>] type LocationRequest = class inherit Object interface IParcelable interface IJavaObject interface IDisposable interface IJavaPeerable
🌐
Codepath
guides.codepath.org › android › Retrieving-Location-with-LocationServices-API
Retrieving Location with LocationServices API | Android Development | CodePath Guides
private LocationRequest mLocationRequest; private long UPDATE_INTERVAL = 10 * 1000; /* 10 secs */ private long FASTEST_INTERVAL = 2000; /* 2 sec */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startLocationUpdates(); ...
Find elsewhere
🌐
Google
codelabs.developers.google.com › codelabs › while-in-use-location
Receive location updates in Android with Kotlin | Google Codelabs
March 27, 2026 - // TODO: Step 1.3, Create a LocationRequest. locationRequest = LocationRequest.create().apply { // Sets the desired interval for active location updates. This interval is inexact. You // may not receive updates at all if no location sources are available, or you may // receive them less frequently than requested. You may also receive updates more // frequently than requested if other applications are requesting location at a more // frequent interval. // // IMPORTANT NOTE: Apps running on Android 8.0 and higher devices (regardless of // targetSdkVersion) may receive updates less frequently than this interval when the app // is no longer in the foreground.
🌐
Google
developers.google.com › google play services › locationrequest.builder
LocationRequest.Builder | Google Play services | Google for Developers
LocationRequest.Builder is used to construct a LocationRequest object · It includes constants for implicit maximum update age and minimum update interval, both set to be the same as the interval
🌐
Android Developers
developer.android.com › api reference › locationrequest.builder
LocationRequest.Builder | 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 · 中文 – 简体
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
Medium
medium.com › @myofficework000 › real-time-location-tracking-made-easy-with-fused-location-provider-43de6437fbd3
Real-Time Location Tracking Made Easy with Fused Location Provider | by Abhishek Pathak | Medium
October 15, 2024 - @SuppressLint("MissingPermission") private fun startLocationUpdates() { val locationRequest = LocationRequest.create().apply { interval = 10000 // 10 seconds fastestInterval = 5000 priority = LocationRequest.PRIORITY_HIGH_ACCURACY } fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, Looper.getMainLooper()) } private val locationCallback = object : LocationCallback() { override fun onLocationResult(locationResult: LocationResult) { locationResult.lastLocation?.let { location -> // Update UI with the new location binding.locationUpdate.text = "Updated Location: ${location.latitude}, ${location.longitude}" } } }
🌐
Meridianapps
files.meridianapps.com › meridian-android-sdk › docs-6.6.0 › com › arubanetworks › meridian › location › LocationRequest.html
LocationRequest (Meridian API)
public static LocationRequest requestCurrentLocation(android.content.Context context, EditorKey appKey, LocationRequest.LocationRequestListener responseListener) Builds and starts a LocationRequest with the given parameters.
🌐
DEV Community
dev.to › johnandout › tips-on-building-android-applications-with-long-running-location-service-using-google-play-location-bpi
Tips on Building Android Applications with Long-running Location Service using Google Play Location API - DEV Community
March 28, 2025 - https://developer.android.com/reference/android/app/Service · class LocationService: Service() { private lateinit var notificationManager: NotificationManager private lateinit var fusedLocationProviderClient: FusedLocationProviderClient private lateinit var locationRequest: LocationRequest private lateinit var locationCallback: LocationCallback override fun onCreate() { notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this) locationRequest = LocationRequest.Builder(10000) .setPriority(...) ...
🌐
GitHub
github.com › codepath › android_guides › wiki › Retrieving-Location-with-LocationServices-API
Retrieving Location with LocationServices API · codepath/android_guides Wiki · GitHub
April 4, 2020 - private LocationRequest mLocationRequest; private long UPDATE_INTERVAL = 10 * 1000; /* 10 secs */ private long FASTEST_INTERVAL = 2000; /* 2 sec */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startLocationUpdates(); } // Trigger new location updates at interval protected void startLocationUpdates() { // Create the location request to start receiving updates mLocationRequest = new LocationRequest(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); mLocationRequest.setInterval(UPDATE_INTERVAL);
Author   codepath
🌐
Google
developers.google.com › google play services › fusedlocationproviderclient
FusedLocationProviderClient | Google Play services | Google for Developers
October 31, 2024 - On the other hand, if repeated location updates are required, such as when tracking the user's location over time, requestLocationUpdates(LocationRequest, Executor, LocationListener) or one of its variants is better suited. Clients are encourage to familiarize themselves with the full range of APIs available in this class to understand which is best suited for their needs. This constant is deprecated. Use Location.isMock() on Android S and above, otherwise use LocationCompat.isMock() from the compat libraries instead.
🌐
Medium
medium.com › @psarakisnick › android-location-manager-with-kotlin-flows-082c992d1b31
Android location manager with Kotlin flows | by Nick Psarakis | Medium
January 21, 2024 - @SuppressLint("MissingPermission") override fun listenToLocation(): Flow<Location> { val request = LocationRequest.Builder(Priority.PRIORITY_BALANCED_POWER_ACCURACY, TimeUnit.MINUTES.toMillis(10)) .setMinUpdateDistanceMeters(1000F) .build() return callbackFlow { if (!hasLocationPermission()) throw NoPermissionsException val locationCallback = object : LocationCallback() { override fun onLocationResult(result: LocationResult) { super.onLocationResult(result) result.lastLocation?.let { launch { send(it) } } } } }
Top answer
1 of 2
40

You are implementing LocationListener in your activity MainActivity. The call for concurrent location updates will therefor be like this:

mLocationClient.requestLocationUpdates(mLocationRequest, this);

Be sure that the LocationListener you're implementing is from the google api, that is import this:

import com.google.android.gms.location.LocationListener;

and not this:

import android.location.LocationListener;

and it should work just fine.

It's also important that the LocationClient really is connected before you do this. I suggest you don't call it in the onCreate or onStart methods, but in onResume. It is all explained quite well in the tutorial for Google Location Api: https://developer.android.com/training/location/index.html

2 of 2
13

I use this one:

LocationManager.requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)

For example, using a 1s interval:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,this);

the time is in milliseconds, the distance is in meters.

This automatically calls:

public void onLocationChanged(Location location) {
    //Code here, location.getAccuracy(), location.getLongitude() etc...
}

I also had these included in the script but didnt actually use them:

public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}

In short:

public class GPSClass implements LocationListener {

    public void onLocationChanged(Location location) {
        // Called when a new location is found by the network location provider.
        Log.i("Message: ","Location changed, " + location.getAccuracy() + " , " + location.getLatitude()+ "," + location.getLongitude());
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {}
    public void onProviderEnabled(String provider) {}
    public void onProviderDisabled(String provider) {}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,this);
    }
}