Is 'constructor LocationRequest()' deprecated in google maps v2?

Viewed 15492

I stumbled upon this message recently, and I was pretty sure that this constructor wasn't deprecated in prior versions to 18.0.0, but I cannot find information anywhere that this one has been deprecated either.

And what should we use instead, is there another way to create a locationRequest ?

message complaining that LocationRequest() is deprecated

5 Answers

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

This line now deprecated: priority = LocationRequest.PRIORITY_HIGH_ACCURACY

replace with priority = Priority.PRIORITY_HIGH_ACCURACY

For anyone who faces this error in geolocator 8.0.1 of Flutter. Try to edit FusedLocationClient.java:199 for now. Then wait for author to update the pub package

From

LocationRequest locationRequest = new LocationRequest();

To

LocationRequest locationRequest = LocationRequest.create();

This is the LocationRequest class enter image description here

UPDATE:

Constant PRIORITY_HIGH_ACCURACY is deprecated use Priority.PRIORITY_HIGH_ACCURACY instead.

 private fun updateLocationTracking(isTracking: Boolean) {
        if(isTracking) {
            if(TrackingUtility.hasLocationPermissions(this)) {
                val request = LocationRequest.create().apply {
                    interval = LOCATION_UPDATE_INTERVAL
                    fastestInterval = FASTEST_LOCATION_INTERVAL
                    priority =  Priority.PRIORITY_HIGH_ACCURACY
                }
} 
 LocationRequest locationRequest = LocationRequest.create() //if you want access of variable
                            .setInterval(100)
                            .setFastestInterval(3000)
                            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                            .setNumUpdates(1)
                            .setMaxWaitTime(100);
Related