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
🌐
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 - Location services were updated to version 21.0.0, and the LocationRequest.create was deprecated with the new update. The changes occurred at 13.
Discussions

LocationRequest() is obsolete and deprecated
Hi @StevenSquires-9060 , are you referring to class LocationRequest in Android? But according to the document, it hasn't been deprecated. You can also check the offical sample here: FusedLocationProvider/MainActivity.cs . ... The attached png file shows what Visual Studio 2019 shows me when I create ... More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
java - How can I create location request in Android? "LocationRequest.create()" is deprecated now - Stack Overflow
LocationRequest.create() "This method is deprecated. Use LocationRequest.Builder instead." says in documentation. More on stackoverflow.com
🌐 stackoverflow.com
LocationRequest deprecated
Hi! flutter run --debug Launching lib\main.dart on SM A528B in debug mode... ...\Pub\Cache\hosted\pub.dartlang.org\geolocator_android-4.1.7\android\src\main\java\com\baseflow\geolocator\location\Fu... More on github.com
🌐 github.com
3
January 31, 2023
Enable Location Service in .NET MAUI after upgrading from Xamarin Forms
I am currently upgrading my Xamarin Forms application to .NET MAUI. In my Xamarin Forms app, I used DependencyService to enable a location pop-up asking the user for location service permission. I'm struggling to find a way to achieve the same result in… More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
March 8, 2024
🌐
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...
🌐
Tomasrepcik
tomasrepcik.dev › blog › 2022 › 2022-10-30-location-request-deprecated
LocationRequest.create() got deprecated. How to fix it?
October 30, 2022 - Here is how to change LocationRequest.create to recommended LocationRequest.Builder: // 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()
🌐
GitHub
github.com › Baseflow › flutter-geolocator › issues › 1206
LocationRequest deprecated · Issue #1206 · Baseflow/flutter-geolocator
January 31, 2023 - LocationRequest deprecated#1206 · Copy link · sisalik1 · opened · on Jan 31, 2023 · Issue body actions · Hi! flutter run --debug Launching lib\main.dart on SM A528B in debug mode...
Author   Baseflow
Find elsewhere
🌐
GitHub
gist.github.com › Foxpace › 94e720e7f5d3d0430f8c07b852bbdc01
Deprecated LocationRequest.create and new Builder · GitHub
Deprecated LocationRequest.create and new Builder. GitHub Gist: instantly share code, notes, and snippets.
Top answer
1 of 1
1

Hello,

Before you start to use Api to access the Google location services, please install following nuget packages in your application.

Xamarin.AndroidX.Fragment.Ktx

Xamarin.GooglePlayServices.Location

Then, Android.Gms.Location.LocationRequest.Create is deprecated. Please use Android.Gms.Location.LocationRequest.Builder to do it.

For MAUI, you do not need to use Dependence service to invoke specific platform code. Please use Conditional compilation

You can refer to the following code.

private async void OnCounterClicked(object sender, EventArgs e)
        {
#if ANDROID
            try
            {
               
                var locationRequest =new Android.Gms.Location.LocationRequest.Builder(Priority.PriorityHighAccuracy,100);
                LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest.Build());
                var response = await LocationServices.GetSettingsClient(Platform.CurrentActivity).CheckLocationSettingsAsync(builder.Build());
            }
            catch (ApiException exception)
            {
                switch (exception.StatusCode)
                {
                    case LocationSettingsStatusCodes.ResolutionRequired:
                        ResolvableApiException resolvable = (ResolvableApiException)exception;
                        resolvable.StartResolutionForResult(Platform.CurrentActivity, 0x1);
                        break;
                    default:
                        break;
                }
            }


#endif
        }

As note: please do not forget to add used Namespace in Conditional compilation.

#if ANDROID
using Android.Gms.Common.Apis;
using Android.Gms.Location;
#endif

Best Regards,

Leon Lu


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

🌐
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 · 中文 – 简体
🌐
Stack Overflow
stackoverflow.com › tags › google-location-services › hot
Hottest 'google-location-services' Answers - Stack Overflow
Yes, the LocationRequest constructor is deprecated. You can use its static method LocationRequest.create() to create a location request.
🌐
GitHub
github.com › ionic-team › capacitor-plugins › issues › 790
LocationRequest() deprecated · Issue #790 · ionic-team/capacitor-plugins
Bug Report Plugin(s) geolocation Capacitor Version 3.x Platform(s) android Current Behavior LocationRequest() constructor is deprecated, switch to LocationRequest.create() Expected Behavior Code Re...
Author   ionic-team
🌐
Medium
tomas--repcik-medium-com.translate.goog › 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 - Location services were updated to version 21.0.0, and the LocationRequest.create was deprecated with the new update. The changes occurred at 13.
🌐
Reddit
reddit.com › r/xamarindevelopers › deprecated
r/xamarindevelopers on Reddit: Deprecated
May 26, 2021 -

I have this code in the start of my application to check if my gps location is true/false and if is false it will pop up a alert so you can choose to enable it.

Its deprecated and i dont know how to fix this anyone who can help me ?

Thank you

[Obsolete]

public async void EnableItGod()

{

try

{

MainActivity activity = Forms.Context as MainActivity;

GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)

.AddApi(LocationServices.API).Build();

googleApiClient.Connect();

LocationRequest locationRequest = LocationRequest.Create();

locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);

locationRequest.SetInterval(10000);

locationRequest.SetFastestInterval(10000 / 2);

LocationSettingsRequest.Builder

locationSettingsRequestBuilder = new LocationSettingsRequest.Builder()

.AddLocationRequest(locationRequest);

locationSettingsRequestBuilder.SetAlwaysShow(false);

LocationSettingsResult locationSettingsResult = await LocationServices.SettingsApi.CheckLocationSettingsAsync

(googleApiClient, locationSettingsRequestBuilder.Build());

if (locationSettingsResult.Status.StatusCode == LocationSettingsStatusCodes.ResolutionRequired)

{

locationSettingsResult.Status.StartResolutionForResult(activity, 0);

}

}

catch (Exception )

{

// GlobalVariables.SendExceptionReport(ex);

}

}

🌐
GitHub
github.com › google › ground-android › issues › 2969
LocationRequest is deprecated · Issue #2969 · google/ground-android
January 2, 2025 - LocationRequest is deprecated#2969 · #2970 · Copy link · Assignees · anandwana001 · opened · on Jan 2, 2025 · Issue body actions · No description provided. Reactions are currently unavailable · anandwana001 · No labels · No labels ...
Author   google
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.