LocationRequest.create() got deprecated. How to fix it?

How to properly ask for location in location services 21.0.0

Tomáš Repčík
1 min readOct 30, 2022

While I was updating one of my projects, I encountered a deprecation warning in my location handling. One whole section while creating the LocationRequest was crossed-out as deprecated.

Image from Iconfinder by Aleksandr Reva

Location services were updated to version 21.0.0, and the LocationRequest.create was deprecated with the new update. The changes occurred at 13. 10. 2022 in the release notes.

Here is how to change LocationRequest.create to recommended LocationRequest.Builder:

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.

New constructors

  • 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
  • LocationRequest.Builder(locationRequest) — other LocationRequest can be used as a starting point for new Builder

The complete example of implementing location request without permission handling is here:

For the whole documentation and setters go here:

Thanks for reading, do not forget to add claps 1 to 50 and follow me for more posts!

--

--

Tomáš Repčík

https://tomasrepcik.dev/ - Flutter app developer with experience in native app development and degree in biomedical engineering.