Yes, the LocationRequest constructor is deprecated. You can use its static method LocationRequest.create() to create a location request.

Kotlin:

locationRequest = LocationRequest.create().apply {
    interval = 100
    fastestInterval = 50
    priority = LocationRequest.PRIORITY_HIGH_ACCURACY
    maxWaitTime = 100
}

Java:

locationRequest = LocationRequest.create()
    .setInterval(100)
    .setFastestInterval(3000) 
    .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
    .setMaxWaitTime(100);

Update

As @Shimon pointed out LocationRequest.PRIORITY_HIGH_ACCURACY is now deprecated, so instead use Priority.PRIORITY_HIGH_ACCURACY

Answer from Kunu on Stack Overflow
🌐
Google
developers.google.com › google play services › locationrequest
LocationRequest | Google Play services | Google for Developers
October 31, 2024 - If this request is Priority.PRIORITY_HIGH_ACCURACY, this will delay delivery of initial low accuracy locations for a small amount of time in case a high accuracy location can be delivered instead. This method is deprecated.
🌐
GitHub
github.com › Lyokone › flutterlocation › issues › 1023
[deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated · Issue #1023 · Lyokone/flutterlocation
March 25, 2025 - [deprecation] PRIORITY_HIGH_ACCURACY in LocationRequest has been deprecated#1023 · Copy link · manuelm12d · opened · on Mar 25, 2025 · Issue body actions · Describe the bug Tengo estos waring con la ultima version del paquete ·
Author   Lyokone
🌐
Medium
tomas-repcik.medium.com › locationrequest-create-got-deprecated-how-to-fix-it-e4f814138764
LocationRequest.create() got deprecated. How to fix it? | by Tomáš Repčík | Medium
October 30, 2022 - Here is how to change ... used by the new Builder of the LocationRequest. LocationRequest.PRIORITY_HIGH_ACCURACY and other values are deprecated too....
🌐
Stack Overflow
stackoverflow.com › tags › google-location-services › hot
Hottest 'google-location-services' Answers - Stack Overflow
This line now deprecated: priority = LocationRequest.PRIORITY_HIGH_ACCURACY replace with priority = Priority.PRIORITY_HIGH_ACCURACY
🌐
Tomasrepcik
tomasrepcik.dev › blog › 2022 › 2022-10-30-location-request-deprecated
LocationRequest.create() got deprecated. How to fix it?
October 30, 2022 - // DEPRECATED // LocationRequest.create().apply { // interval = timeInterval // smallestDisplacement = minimalDistance // priority = LocationRequest.PRIORITY_HIGH_ACCURACY // } // New builder LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, timeInterval).apply { setMinUpdateDistanceMeters(minimalDistance) setGranularity(Granularity.GRANULARITY_PERMISSION_LEVEL) setWaitForAccurateLocation(true) }.build()
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 381345 › locationrequest()-is-obsolete-and-deprecated
LocationRequest() is obsolete and deprecated - Microsoft Q&A
Yes, the LocationRequest constructor is deprecated. You can use its static method: ... void CreateLocationRequest() { // mLocationRequest = new LocationRequest(); mLocationRequest = LocationRequest.Create(); mLocationRequest.SetInterval(UPD...
🌐
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.
🌐
Airnativeextensions
docs.airnativeextensions.com › asdocs › location › com › distriqt › extension › location › LocationRequest.html
com.distriqt.extension.location.LocationRequest
public function setPersistInBackground(persistInBackground:Boolean = true, notificationText:String = null):LocationRequest ... To request "block" level accuracy. Block level accuracy is considered to be about 100 meter accuracy. Using a coarse accuracy such as this often consumes less power. On iOS this will use both standard and significant update modes. If you only have the "in-use" permission then you will not get significant updates but only the standard updates. public static const PRIORITY_HIGH_ACCURACY:int = 0
🌐
GitHub
github.com › BirjuVachhani › locus-android › issues › 82
Update Documentation for LocationRequest Configuration (Release v4.1.1) · Issue #82 · BirjuVachhani/locus-android
Deprecated code snippet: Locus.configure { request { fastestInterval = 1000 priority = LocationRequest.PRIORITY_HIGH_ACCURACY interval = 1000 maxWaitTime = 2000 } } 👍4 · No one assigned · No labels · No labels · No projects · No milestone · None yet · No branches or pull requests ·
Author   BirjuVachhani
Top answer
1 of 7
161

Original Answer

This is happening because FusedLocationProviderApi deprecated in a recent version of google play services. You can check it here. The official guide now suggests using FusedLocationProviderClient. You can find the detailed guide here.

for e.g inside onCreate() or onViewCreated() create a FusedLocationProviderClient instance

Kotlin

val fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireContext())

and for requesting the last known location all you have to do is call

fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
            location?.let { it: Location ->
                // Logic to handle location object
            } ?: kotlin.run {
                // Handle Null case or Request periodic location update https://developer.android.com/training/location/receive-location-updates
            }
        }

Java

FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireContext());

and

fusedLocationClient.getLastLocation().addOnSuccessListener(requireActivity(), location -> {
        if (location != null) {
            // Logic to handle location object
        } else {
            // Handle null case or Request periodic location update https://developer.android.com/training/location/receive-location-updates
        }
    });

Simple, Isn't it?


Important Update (October 24, 2017):

Yesterday Google updated its official developer page with a warning that says

Please continue using the FusedLocationProviderApi class and don't migrate to the FusedLocationProviderClient class until Google Play services version 12.0.0 is available, which is expected to ship in early 2018. Using the FusedLocationProviderClient before version 12.0.0 causes the client app to crash when Google Play services is updated on the device. We apologize for any inconvenience this may have caused.

So I think we should continue using the deprecated LocationServices.FusedLocationApi until Google resolves the issue.


Latest Update (November 21, 2017):

The warning is gone now. Google Play services 11.6 November 6, 2017, release note says : I think Play Services won't crash when it updates itself in the background. So we can use new FusedLocationProviderClient now.

2 of 7
15
   // Better to use GoogleApiClient to show device location. I am using this way in my aap.

    public class SuccessFragment extends Fragment{
        private TextView txtLatitude, txtLongitude, txtAddress;
        // private AddressResultReceiver mResultReceiver;
        // removed here because cause wrong code when implemented and
        // its not necessary like the author says

        //Define fields for Google API Client
        private FusedLocationProviderClient mFusedLocationClient;
        private Location lastLocation;
        private LocationRequest locationRequest;
        private LocationCallback mLocationCallback;

        private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 14;

        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_location, container, false);

            txtLatitude = (TextView) view.findViewById(R.id.txtLatitude);
            txtLongitude = (TextView) view.findViewById(R.id.txtLongitude);
            txtAddress = (TextView) view.findViewById(R.id.txtAddress);

            // mResultReceiver = new AddressResultReceiver(null);
            // cemented as above explained
            try {
                mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getActivity());
                mFusedLocationClient.getLastLocation()
                        .addOnSuccessListener(getActivity(), new OnSuccessListener<Location>() {
                            @Override
                            public void onSuccess(Location location) {
                                // Got last known location. In some rare situations this can be null.
                                if (location != null) {
                                    // Logic to handle location object
                                    txtLatitude.setText(String.valueOf(location.getLatitude()));
                                    txtLongitude.setText(String.valueOf(location.getLongitude()));
                                    if (mResultReceiver != null)
                                        txtAddress.setText(mResultReceiver.getAddress());
                                }
                            }
                        });
                locationRequest = LocationRequest.create();
                locationRequest.setInterval(5000);
                locationRequest.setFastestInterval(1000);
                if (txtAddress.getText().toString().equals(""))
                    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
                else
                    locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

                mLocationCallback = new LocationCallback() {
                    @Override
                    public void onLocationResult(LocationResult locationResult) {
                        for (Location location : locationResult.getLocations()) {
                            // Update UI with location data
                            txtLatitude.setText(String.valueOf(location.getLatitude()));
                            txtLongitude.setText(String.valueOf(location.getLongitude()));
                        }
                    }

                    ;
                };
            } catch (SecurityException ex) {
                ex.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return view;
        }

        @Override
        public void onStart() {
            super.onStart();

            if (!checkPermissions()) {
                startLocationUpdates();
                requestPermissions();
            } else {
                getLastLocation();
                startLocationUpdates();
            }
        }

        @Override
        public void onPause() {
            stopLocationUpdates();
            super.onPause();
        }

        /**
         * Return the current state of the permissions needed.
         */
        private boolean checkPermissions() {
            int permissionState = ActivityCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_COARSE_LOCATION);
            return permissionState == PackageManager.PERMISSION_GRANTED;
        }

        private void startLocationPermissionRequest() {
            ActivityCompat.requestPermissions(getActivity(),
                    new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                    REQUEST_PERMISSIONS_REQUEST_CODE);
        }


        private void requestPermissions() {
            boolean shouldProvideRationale =
                    ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                            Manifest.permission.ACCESS_COARSE_LOCATION);

            // Provide an additional rationale to the user. This would happen if the user denied the
            // request previously, but didn't check the "Don't ask again" checkbox.
            if (shouldProvideRationale) {
                Log.i(TAG, "Displaying permission rationale to provide additional context.");

                showSnackbar(R.string.permission_rationale, android.R.string.ok,
                        new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                // Request permission
                                startLocationPermissionRequest();
                            }
                        });

            } else {
                Log.i(TAG, "Requesting permission");
                // Request permission. It's possible this can be auto answered if device policy
                // sets the permission in a given state or the user denied the permission
                // previously and checked "Never ask again".
                startLocationPermissionRequest();
            }
        }

        /**
         * Callback received when a permissions request has been completed.
         */
        @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                               @NonNull int[] grantResults) {
            Log.i(TAG, "onRequestPermissionResult");
            if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
                if (grantResults.length <= 0) {
                    // If user interaction was interrupted, the permission request is cancelled and you
                    // receive empty arrays.
                    Log.i(TAG, "User interaction was cancelled.");
                } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // Permission granted.
                    getLastLocation();
                } else {
                    // Permission denied.

                    // Notify the user via a SnackBar that they have rejected a core permission for the
                    // app, which makes the Activity useless. In a real app, core permissions would
                    // typically be best requested during a welcome-screen flow.

                    // Additionally, it is important to remember that a permission might have been
                    // rejected without asking the user for permission (device policy or "Never ask
                    // again" prompts). Therefore, a user interface affordance is typically implemented
                    // when permissions are denied. Otherwise, your app could appear unresponsive to
                    // touches or interactions which have required permissions.
                    showSnackbar(R.string.permission_denied_explanation, R.string.settings,
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    // Build intent that displays the App settings screen.
                                    Intent intent = new Intent();
                                    intent.setAction(
                                            Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                    Uri uri = Uri.fromParts("package",
                                            BuildConfig.APPLICATION_ID, null);
                                    intent.setData(uri);
                                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    startActivity(intent);
                                }
                            });
                }
            }
        }


        /**
         * Provides a simple way of getting a device's location and is well suited for
         * applications that do not require a fine-grained location and that do not need location
         * updates. Gets the best and most recent location currently available, which may be null
         * in rare cases when a location is not available.
         * <p>
         * Note: this method should be called after location permission has been granted.
         */
        @SuppressWarnings("MissingPermission")
        private void getLastLocation() {
            mFusedLocationClient.getLastLocation()
                    .addOnCompleteListener(getActivity(), new OnCompleteListener<Location>() {
                        @Override
                        public void onComplete(@NonNull Task<Location> task) {
                            if (task.isSuccessful() && task.getResult() != null) {
                                lastLocation = task.getResult();

                                txtLatitude.setText(String.valueOf(lastLocation.getLatitude()));
                                txtLongitude.setText(String.valueOf(lastLocation.getLongitude()));

                            } else {
                                Log.w(TAG, "getLastLocation:exception", task.getException());
                                showSnackbar(getString(R.string.no_location_detected));
                            }
                        }
                    });
        }

        private void stopLocationUpdates() {
            mFusedLocationClient.removeLocationUpdates(mLocationCallback);
        }

        private void startLocationUpdates() {
            if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), 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;
            }
            mFusedLocationClient.requestLocationUpdates(locationRequest, mLocationCallback, null);
        }

        // private void showSnackbar(final String text) {
        //    if (canvasLayout != null) {
        //        Snackbar.make(canvasLayout, text, Snackbar.LENGTH_LONG).show();
        //    }
        //}
        // this also cause wrong code and as I see it dont is necessary
        // because the same method which is really used


        private void showSnackbar(final int mainTextStringId, final int actionStringId,
                                  View.OnClickListener listener) {
            Snackbar.make(getActivity().findViewById(android.R.id.content),
                    getString(mainTextStringId),
                    Snackbar.LENGTH_INDEFINITE)
                    .setAction(getString(actionStringId), listener).show();
        }
    }

And our fragment_location.xml

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/locationLayout"
            android:layout_below="@+id/txtAddress"
            android:layout_width="match_parent"
            android:layout_height="@dimen/activity_margin_30dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtLatitude"
                android:layout_width="@dimen/activity_margin_0dp"
                android:layout_height="@dimen/activity_margin_30dp"
                android:layout_weight="0.5"
                android:gravity="center"
                android:hint="@string/latitude"
                android:textAllCaps="false"
                android:textColorHint="@color/colorPrimaryDark"
                android:textColor="@color/colorPrimaryDark" />

            <TextView
                android:id="@+id/txtLongitude"
                android:layout_width="@dimen/activity_margin_0dp"
                android:layout_height="@dimen/activity_margin_30dp"
                android:layout_weight="0.5"
                android:gravity="center"
                android:hint="@string/longitude"
                android:textAllCaps="false"
                android:textColorHint="@color/colorPrimary"
                android:textColor="@color/colorPrimary" />
        </LinearLayout>
🌐
GitHub
github.com › Baseflow › flutter-geolocator › issues › 1124
9.0.1 deprecation in android build with sdk 33 · Issue #1124 · Baseflow/flutter-geolocator
August 22, 2022 - Task :geolocator_android:compi... return LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; ^ /Users/hesham/.pub-cache/hosted/pub.dartlang.org/geolocator_android-4.0.2/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java:228: warning: [deprecation] PRIORITY_HIGH_ACCURACY in ...
Author   Baseflow
🌐
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 · 中文 – 简体
🌐
Stack Overflow
stackoverflow.com › questions › 51587804 › locationrequest-priority-high-accuracy-not-working-in-api-21
android - LocationRequest.PRIORITY_HIGH_ACCURACY not working in API 21 - Stack Overflow
July 30, 2018 - LocationRequest smallest displacement and accuracy · 0 · Setting priority as PRIORITY_HIGH_ACCURACY in the LocationRequest keeps GPS on indefinitely · 4 · Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations in android 6 ·
🌐
Stack Overflow
stackoverflow.com › questions › 49150328 › android-location-request-priority-high-accuracy-has-no-effect
Android location request PRIORITY_HIGH_ACCURACY has no effect - Stack Overflow
March 7, 2018 - This works as intended on a Huawei phone, but fails on Samsung S7 and S8: If the user has selected Power balanced, a dialog appears and the location tracking is set to high accuracy. However, if GPS only was selected previously, the ApiException is not thrown and the setting stays the same. val locationRequest = LocationRequest.create() locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest) val result = LocationServices.getSettingsClient(this).checkLocationSettings(builder.build()) result.addOnCompleteListener(OnCompleteListener { try { it.getResult(ApiException::class.java) // on Samsung + GPS only setting, execution passes here, no ApiException thrown } catch(e: ApiException) { if(e is ResolvableApiException) { // ...show resolution dialog...
🌐
Javafixing
javafixing.com › 2022 › 06 › fixed-is-locationrequest-deprecated-in.html
[FIXED] Is 'constructor LocationRequest()' deprecated in google maps v2? ~ JavaFixing
June 26, 2022 - Yes, the LocationRequest constructor is deprecated. You can use its static method LocationRequest.create() to create a location request. ... locationRequest = LocationRequest.create().apply { interval = 100 fastestInterval = 50 priority = ...