Library for fetching location in Android

Maheshchakkarwar
1 min readMay 28, 2022

LocationAPI helps to fetch location of device in your application. Location API comes with android play services. If you are looking for fetching location in Activity or fragment, this blog will helps you to implement that😊.

I have published a library that deals with checking location permission and GPS settings;

Use below steps to integrate in your application;

  1. Add below repository into global build.gradle;
repositories {
maven { url 'https://jitpack.io' }
}
  1. Add below dependency as app level build.gradle;
dependencies {
implementation 'com.github.mchakkarwar:LocationLibrary:0.0.2'
}

3. Implment below callback LocationCallbacks;

interface LocationCallbacks {
fun onLocationReceived(location: UsersLocation) // use this callback to receive user's location
fun onAccessLocationGranted() // This callback is called after location permission granted
fun onAccessLocationDenied() // This callback is called if user denied location permission
fun onLocationSettingEnabled() // This callback is called after enabled GPS settings
fun onLocationSettingDisabled() // This callback is called after disabling GPS settings
}

4. Create LocationClient instance as below

val locationClient = LocationClient(
locationCallbacks = this,
context = this,
interval = 100,
fastestInterval = 100,
locationType = HIGH_ACCURACY
)

5. Add LocationClient as lifecycle observer

lifecycle.addObserver(locationClient)

Git Repository:

--

--

Maheshchakkarwar

A enthusiastic Android Developer like to learn new things and share to everyone.