Skip to content
Birju Vachhani edited this page Mar 8, 2019 · 9 revisions

Locus-Android

Locus is a life-cycle aware android library for retrieving location updates by writing just a few lines. It uses Google's FusedLocationProviderApi to retrieve location and uses LiveData to notify observers on location updates.

Current Version 3.0.0-alpha01
Platform Android
Language Kotlin
SDK Level 16+
License Apache 2.0
Size 49 KB

Topics

Features

  • Completely written in Kotlin
  • Easy Initialization
  • Handles Permission Model
  • No Boilerplate
  • Built on Kotlin DSL
  • Manifest Permission Check
  • Life-Cycle Aware Location Updates
  • Location Settings Check
  • Location Settings Request
  • Custom Location Options Configuration
  • Custom Relation Dialog configuration
  • Custom Permission Blocked Dialog configuration

Installation

Gradle Dependency

  • Add the JitPack repository to your project level build.gradle file.
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Add the library dependency in your app level build.gradle file.
dependencies {
    implementation 'com.github.BirjuVachhani:locus-android:3.0.0-alpha01'
}

Usage

1. Init Locus Class

Activity/Fragment

private val locus = Locus(this)

2. Retrieve Location

Retrieve Location Only Once

locus.getCurrentLocation(this) {
    Log.e(TAG, "Latitude: $latitude\tLongitude: $longitude")
}

To handle errors:

locus.getCurrentLocation(this) {
    Log.e(TAG, "Latitude: $latitude\tLongitude: $longitude")
} failure {
    when {
        isDenied -> Log.e(TAG, "Permission denied")
        isPermanentlyDenied -> Log.e(TAG, "Permission is blocked")
        else -> Log.e(TAG, "something went wrong!")
    }
}

Continuous Location

locus.listenForLocation(this) {
    Log.e(TAG, "Latitude: $latitude\tLongitude: $longitude")
}

To handle errors:

locus.listenForLocation(this) {
    Log.e(TAG, "Latitude: $latitude\tLongitude: $longitude")
} failure {
    when {
        isDenied -> Log.e(TAG, "Permission denied")
        isPermanentlyDenied -> Log.e(TAG, "Permission is blocked")
        else -> Log.e(TAG, "something went wrong!")
    }
}

3. Stop Receiving Location

locus.stopTrackingLocation()

So easy right? That's what we wanted to achieve: a hassle free location retrieval process.

License

   Copyright  2019 BirjuVachhani

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
Clone this wiki locally