Retrieve Location Using Locus LibraryOctober 08, 2021 Publish By : EXPERT APP DEVS 2 min read Viewed By : 606
Retrieving location update is a tedious one as we have to handle all the scenarios whether a user has enabled GPS or not, handling location permission in manifest, and getting accurate location. All these are very frustrating from the developer point of view. For fetching location we have to define
And an additional one keeping android 10 in mind
We have to handle location updates when some activity/fragment gets initialized and have to destroy it in onDestroy().
To overcome this boilerplate code, there is an awesome library Locus that will solve our problem in just 3 lines of code.
Locus includes many such features that are time-saving for developers.
- Built using Kotlin DSL
- Supports Android 10 Location permission changes.
- Supports Location Resolution
- Easy Configuration
- Highly customizable
- Lifecycle aware
Locus is built using Kotlin DSL which makes it so beautiful to write and customize easily. Also, Locus uses LiveData internally to make its lifecycle aware so you don’t have to worry about your fragment/activity lifecycle anymore.
In the project-level build.gradle, paste the below code.
Add this dependency to your build.gradle(app-level):
Latest_version = 3.2.0
Retrieving Continuous Location Update
By just adding the below chunk of code in either activity or fragment, we'll get location updates.
The following scenario is handled by default with this library
- Android Permission model with default relational texts
- For getting high-resolution location updates, Location settings have been managed.
- Lifecycle aware out of the box.
Retrieving Location Update at Once
Add below the line of code when you want to retrieve location update only once.
Stop Receiving Location Update
Stopping location updates is quite easy and clean. Just add the below line of code and done.
Handling Denials Scenario
Locus notifies you when a user denies location access or location settings resolution. When you receive an error from the locus, the error object can be used to check for these denials.
Locus makes a developers’ life very easy when it comes to retrieving location. It is highly customizable and will fulfill most of the requirements that a developer needs.
Need a consultation?
Drop us a line! We are here to answer your questions 24/7.