For me, it was because I used the wrong import.

Try using the right one:

import com.google.android.gms.location.LocationRequest;
Answer from LANAH PHENG 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 - Fields of LocationRequest used to be filled upon the creation of the LocationRequest. However, new setters are used by the new Builder of the LocationRequest. LocationRequest.PRIORITY_HIGH_ACCURACY and other values are deprecated too. LocationRequest.Builder(timeInterval) — time in milliseconds, how often you want to get location updates · LocationRequest.Builder(Priority, timeInterval) — same as above + priority, which now has a separate interface with the same values as before
🌐
Stack Overflow
stackoverflow.com › questions › 78039846 › cannot-resolve-method-create-in-locationrequest
java - Cannot resolve method 'create' in 'LocationRequest' - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... locationRequest=LocationRequest.create(); //create() function is not identify and i am using the latest version com.google.android.gms:play-services-location:21.1.0 and but still getting this error please solve my query.
🌐
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.
🌐
Codepath
guides.codepath.org › android › Retrieving-Location-with-LocationServices-API
Retrieving Location with LocationServices API | Android Development | CodePath Guides
You can remove ACCESS_FINE_LOCATION this will still work with less precision. Note: The permissions model has changed starting in Marshmallow. If your targetSdkVersion >= 23 and you are running on a Marshmallow (or later) device, you may need to enable runtime permissions. You can also read more about the runtime permissions changes here. Inside an Activity, put the following to connect and start receiving location updates: 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.
🌐
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 · 中文 – 简体
🌐
Google
developers.google.com › google play services › locationrequest
LocationRequest | Google Play services | Google for Developers
October 31, 2024 - This method is deprecated. Use LocationRequest.Builder instead. May be removed in a future release. The duration of this request. A location request will not receive any locations after it has expired, and will be removed shortly thereafter.
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
void CreateLocationRequest() { // mLocationRequest = new LocationRequest(); mLocationRequest = LocationRequest.Create(); mLocationRequest.SetInterval(UPDATE_INTERVAL); mLocationRequest.SetFastestInterval(FASTEST_INTERVAL); mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); mLocationRequest.SetSmallestDisplacement(DISPLACEMENT); locationClient = LocationServices.GetFusedLocationProviderClient(this); } ... 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.
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.

🌐
Java Tips
javatips.net › api › com.google.android.gms.location.locationrequest
Java Examples for com.google.android.gms.location.LocationRequest
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 1. setContnetView setContentView(R.layout.activity_main); // 2. get reference to TextView txtLong = (TextView) findViewById(R.id.txtLong); txtLat = (TextView) findViewById(R.id.txtLat); // 3. create LocationClient mLocationClient = new LocationClient(this, this, this); // 4. create & set LocationRequest for Location update mLocationRequest = LocationRequest.create(); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the update interval to 5 seconds mLocationRequest.s
🌐
GitHub
github.com › Baseflow › flutter-geolocator › issues › 1206
LocationRequest deprecated · Issue #1206 · Baseflow/flutter-geolocator
January 31, 2023 - ...\Pub\Cache\hosted\pub.dartlang.org\geolocator_android-4.1.7\android\src\main\java\com\baseflow\geolocator\location\FusedLocationClient.java:86: warning: [deprecation] create( ) in LocationRequest has been deprecated LocationRequest locationRequest = LocationRequest.create(); ^ ...\Pub\Cache\hosted\pub.dartlang.org\geolocator_android-4.1.7\android\src\main\java\com\baseflow\geolocator\location\FusedLocationClient.java:89: warning: [deprecation] setPrio rity(int) in LocationRequest has been deprecated locationRequest.setPriority(toPriority(options.getAccuracy())); ^ ...\Pub\Cache\hosted\pub.d
Author   Baseflow
🌐
Stack Overflow
stackoverflow.com › questions › 61860833 › requestlocationupdates-doesnt-call-the-locationcallback
android - requestLocationUpdates doesn't call the locationCallback - Stack Overflow
{ finish(); } }).show() } ... is working!") } } if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { println("This app hasn't permission to access users location") return; } val locationRequest = LocationRequest.create() val fifteen ...
🌐
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 › change location settings
Change location settings | Sensors and location | Android Developers
The following code snippet shows how to determine whether the user's location settings allow location services to create a LocationRequest, as well as how to ask the user for permission to change the location settings if necessary: task.addOnSuccessListener { locationSettingsResponse -> // All location settings are satisfied. The client can initialize // location requests here. // ... } task.addOnFailureListener { exception -> if (exception is ResolvableApiException){ // Location settings are not satisfied, but this can be fixed // by showing the user a dialog.
🌐
GitHub
github.com › mcharmas › Android-ReactiveLocation › issues › 43
Location updates not working when WiFi is enabled. · Issue #43 · mcharmas/Android-ReactiveLocation
Notifications · Fork 319 · Star 2.1k · New issue · Jump to bottom · Closed · 2bard opened this issue · May 8, 2015 · 3 comments · Closed · 2bard opened this issue · May 8, 2015 · 3 comments · Copy link · Apologies if i'm doing something wrong here. I'm subscribing for location updates but I only get the updates when wifi is turned off · My code: LocationRequest request = LocationRequest.create() //standard GMS LocationRequest .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setSmallestDisplacement(0.1f) .setNumUpdates(5) .setInterval(100); Subscription subscription = locationProvider.getUpdatedLocation(request) .subscribe(new Action1<Location>() { @Override public void call(Location location) { //do stuff } }); As soon as I disable wifi I start receiving the updates.
Author   mcharmas