An Awesome Kotlin Location library to retrieve location merely in 3 lines of code

Overview

banner

Locus-Android

License language Platform API Release

Locus is a tiny kotlin library for android which makes it super very easy to retrieve location with just few lines of code. Everything including permission model and Location settings resolution is handled internally which removes a lot of boilerplate code any developer have to write every time.

See Wiki for more information and configuration!

Read blog here: The Legendary Task of Retrieving Location in Just 3 lines of code.

Features

  • Android R support (Please report if any issue is found)
  • 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

IMPORTANT: Deprecation from v3.2.0

Text Customizations using Locus.configure{} block is deprecated in v3.2.0. That means rationaleText, rationaleTitle, blockedTitle, blockedText, resolutionTitle, and resolutionText are deprecated. Migration would be to customize/override them from strings.xml.

It is deprecated in v3.2.0 and will be removed completely in next release.

Before

Locus.configure {
    rationaleTitle = "Rationale Title"
    rationaleTitle = "This is a rationale message."
    blockedTitle = "Permission Blocked Title"
    blockedText = "This is a permission blocked message."
    resolutionTitle = "Permission Resolution Title"
    resolutionText = "This is a permission resolution message."
}

Now

strings.xml

Rationale Title This is a rationale message. Permission Blocked Title This is a permission blocked message. Permission Resolution Title This is a permission resolution message. ">
<string name="locus_rationale_title">Rationale Titlestring>
<string name="locus_rationale_message">This is a rationale message.string>
<string name="locus_permission_blocked_title">Permission Blocked Titlestring>
<string name="locus_permission_blocked_message">This is a permission blocked message.string>
<string name="locus_location_resolution_title">Permission Resolution Titlestring>
<string name="locus_location_resolution_message">This is a permission resolution message.string>

checkout strings.xml.

Gradle Dependency

  • Add the JitPack repository to your project's build.gradle file
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • Add the dependency in your app's build.gradle file
dependencies {
    implementation 'com.github.BirjuVachhani:locus-android:latest-version'
    implementation 'com.google.android.gms:play-services-location:latest-version'
}

Usage

See Wiki on how to get started with Locus.

Pull Request

To generate a pull request, please consider following Pull Request Template.

Issues

To submit an issue, please check the Issue Template.

Code of Conduct

Code of Conduct

Contribution

You are most welcome to contribute to this project!

Please have a look at Contributing Guidelines, before contributing and proposing a change.

Buy Me A Coffee

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.
Comments
  • Pending intents need to have either FLAG_IMMUTABLE or FLAG_MUTABLE

    Pending intents need to have either FLAG_IMMUTABLE or FLAG_MUTABLE

    When trying to run my app on an API 31 emulator, I get a crash with the following stack track:

    java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. at android.app.PendingIntent.checkFlags(PendingIntent.java:375) at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) at android.app.PendingIntent.getBroadcast(PendingIntent.java:632) at com.birjuvachhani.locus.LocationBroadcastReceiver$Companion.getPendingIntent(LocationBroadcastReceiver.kt:41) at com.birjuvachhani.locus.LocationProvider$pendingIntent$2.invoke(LocationProvider.kt:40) at com.birjuvachhani.locus.LocationProvider$pendingIntent$2.invoke(LocationProvider.kt:39) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.birjuvachhani.locus.LocationProvider.getPendingIntent(LocationProvider.kt:39) at com.birjuvachhani.locus.LocationProvider.startUpdates$locus_release(LocationProvider.kt:56) at com.birjuvachhani.locus.Locus.startUpdates(Locus.kt:248) at com.birjuvachhani.locus.Locus.access$startUpdates(Locus.kt:81) at com.birjuvachhani.locus.Locus$checkAndStartLocationUpdates$2.invoke(Locus.kt:209) at com.birjuvachhani.locus.Locus$checkAndStartLocationUpdates$2.invoke(Locus.kt:206) at com.birjuvachhani.locus.Locus.checkLocationSettings$lambda-3(Locus.kt:233) at com.birjuvachhani.locus.Locus.$r8$lambda$9D3IJ2F1aenyoyH999DecV6GSsU(Unknown Source:0) at com.birjuvachhani.locus.Locus$$ExternalSyntheticLambda3.onSuccess(Unknown Source:4) at com.google.android.gms.tasks.zzn.run(com.google.android.gms:play-services-tasks@@17.2.0:4) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

    bug 
    opened by Zee-BA 16
  • location_settings_denied returned while enabling the location.

    location_settings_denied returned while enabling the location.

    Describe the bug When the device's location is turned off then the app requests to enable location after you enable it, it will return location_settings_denied

    To Reproduce Steps to reproduce the behavior:

    1. Turn off your locatoin.
    2. Go to your app that uses this library.
    3. Request to get Locus.getCurrentLocation
    4. Enable location
    5. See error

    Expected behavior After enabling the location should retry to get the location instead returning location_settings_denied

    Smartphone (please complete the following information):

    • Device: Samsung A70
    • OS: Android
    • Version: Android 11
    bug Hacktoberfest 
    opened by kosratdev 15
  • Not receiving location updates while screen is off

    Not receiving location updates while screen is off

    Describe the bug Hi, i use your library in a foreground service, when device is unlocked it gets location updates, but when device is locked it doesn't get location update, can you please help me with this?

    Expected behavior should receive location updates when device is locked.

    Smartphone (please complete the following information):

    • Device: Xiaomi Redmi Note 9 Pro
    • OS: Android
    • Version 10
    opened by nicemak 12
  • Accurate current Location is invalid

    Accurate current Location is invalid

    Describe the bug The library doesn't support to get user current location and it's depend on google map location to retrieve the last known location, please can you solve it @BirjuVachhani

    To Reproduce Steps to reproduce the behavior: 1- open app 2- request to get current location (Locus.getCurrentLocation())

    Expected behavior I expected to retrieve the user current location instead of the last known location

    Smartphone (please complete the following information):

    • Any version
    opened by khaboshama91 10
  • Background permission getting added in the merged manifest

    Background permission getting added in the merged manifest

    Describe the bug I loved locus, the implementation was really easy and it handles everything but the only issue is that I do not need background location updates, i only need it on demand, but after implementing locus Background permission is getting added to the merged manifest as well and so i have an issue in uploading it on the play store.

    To Reproduce Steps to reproduce the behavior:

    1. Import locus
    2. Check merged manifest Expected behavior

    As mentioned i require the location only on demand, so is it possible to get only that and not have to take the background location permission?

    Thanks in advance! Screenshot 2021-09-27 at 1 24 24 PM ce

    Hacktoberfest 
    opened by rananhffc 9
  • Changing the style of dialogs and disabling them.

    Changing the style of dialogs and disabling them.

    Is it possible to customize the styling of the dialogs ? I have a problem with the settings resolution dialog, the buttons are displayed in red.

    also is it possible to disable the settings resolution dialog ? because it's unnecessary as Google already shows one so it would be awesome if you provide an option to either show it or not

    enhancement 
    opened by OmarELRayes 5
  • if location disabled in settings it ask to enable location in settings but can't get location after enable it.

    if location disabled in settings it ask to enable location in settings but can't get location after enable it.

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by vicky-droid 4
  • I have a foreground service, how to Locus in that service

    I have a foreground service, how to Locus in that service

    I want to use locus in my foreground Service. Hello, I want to access location when my application is in background for this i have created a foreground service in my app, but im unable to use locus in foreground service as it is asking for instance of fragment, Kindly give me some sample code that how can i use this library if foreground service ?

    opened by yasirahmedkhan 4
  • java.lang.Throwable: location_settings_denied if using mock location

    java.lang.Throwable: location_settings_denied if using mock location

    Describe the bug location_settings_denied if using mock location

    To Reproduce Install any mock location app (tested with FakeGPS Free) Request location Throws error, seems like it considers location disabled

    bug Hacktoberfest 
    opened by amanzan 3
  • Some help needed

    Some help needed

    Thanks for the great library.

    My questions are:

    1- How to get location if internet (wifi / mobile data) is off, GPS only? 2- If GPS is off how can we turn on location programmatically? Can you put this feature in your library?

    Thank you once again for this library.

    help wanted 
    opened by nicemak 3
  • Failed to resolve dependency

    Failed to resolve dependency

      > Could not find locus-android-4.1.0.aar (com.github.BirjuVachhani:locus-android:4.1.0).
            Searched in the following locations:
                https://jitpack.io/com/github/BirjuVachhani/locus-android/4.1.0/locus-android-4.1.0.aar
    
    opened by mirceasotan 2
  • Github Action not working with Locus

    Github Action not working with Locus

    Thank you for your library, however there is some problem in integrating with Github Action :

    Describe the bug Cannot Implement locus with Github Action

    To Reproduce Run build build android in github action with locus implemented

    Expected behavior the build is successful

    Screenshots image

    opened by arifinreinaldo 1
  • Android Api 30 get current location

    Android Api 30 get current location

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Start android API 30
    2. call getCurrentLocation
    3. Current location is null

    Expected behavior For some reason, the same piece of code works for Android 33 but doesn't work for 30... Trying to use getCurrentLocation

    Screenshots SCR-20221024-n9f SCR-20221024-n8y

    opened by romanfurman6 1
  • Location Issuse

    Location Issuse

    Location not provided when enabling location button

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    opened by virendersran01 1
  • Dialog while request background location

    Dialog while request background location

    Is your feature request related to a problem? Please describe. No

    Describe the solution you'd like Show the popup before requesting for background location service all the time. It's better to have alert dialog with new string fields for the message.

    Describe alternatives you've considered Changed the location request message to reflect the changes.

    Additional context You can find the full screenshots at: https://imgur.com/a/L7fClCO

    opened by subashz 0
  • On-Click of Deny button Dismiss Permission Alert

    On-Click of Deny button Dismiss Permission Alert

    Permission Currently, OnClick of Deny, It is asking/showing again and again.

    Solution OnClick of Deny, the Permission Dialog should be dismissed.

    Alternative Not a good approach, Surrounded it with Dexter permission handling

    opened by dharamveer-roundr 3
Releases(4.1.0)
Owner
Birju Vachhani
Lead Engineer @SimformSolutionsPvtLtd | Android | Flutter | Kotlin | Dart | Ruby
Birju Vachhani
A library for otp view with gradient and lines

AndroidOtpView (With gradient color in lines) Preview Otp View library for Android Getting started Add it in your root build.gradle at the end of repo

Poonam Parth 19 Feb 14, 2022
AndroRAT is a tool designed to give the control of the android system remotely and retrieve informations from it.

AndroRAT is a tool designed to give the control of the android system remotely and retrieve informations from it. Androrat is a client/server application developed in Java Android for the client side and the Server is in Python.

Neeraj Singh 1.5k Dec 30, 2022
Location-history-viewer - Small compose-desktop app to view data from google's location history

Google Location History Takeout Viewer This application provides a minimalistic

Chris Stelzmüller 3 Jun 23, 2022
Location-permission-handler - Location Permission Handler For Android

Location Permission Handler Easy way to check location permissions for Android 9

null 1 Feb 1, 2022
An awesome collaborative collection of Kotlin Multiplatform libraries

Awesome Kotlin Multiplatform Awesome Projects Updated 33 November 21, 2021 Contents Guides Dependency Injection Database NoSQL SQL Extension Reactive

Matteo Crippa 5 Dec 12, 2022
A collaborative list of awesome jetpack compose resources.

Awesome Jetpack compose A collaborative list of awesome jetpack compose resources. Featured in Content Official Documentation Conference talks Article

Naveen T P 289 Nov 15, 2022
An awesome list that curates the best KMM libraries, tools and more.

Awesome KMM Kotlin Multiplatform Mobile (KMM) is an SDK designed to simplify creating cross-platform mobile applications. With the help of KMM, you ca

Konstantin 994 Dec 28, 2022
Whereabouts: an android library which leverages Kotlin concurrency to streamline location fetching

Whereabouts Whereabouts is an android library which leverages Kotlin concurrency

Sumeet Rukeja 1 Jul 5, 2022
Location Service Manager for Kotlin Multiplatform Mobile iOS and android

Location Service Manager for Kotlin Multiplatform Mobile iOS and android Features Provides simple permission settings Dramatically reduce the amount o

LINE 55 Dec 10, 2022
Sample Project with Clean Architecture for demonstrating using Kotlin Flows for fetching User Location and networking.

Nearby-Places-Foursquare-Android Getting Nearby Places using Foursquare API API's Used from FourSquare Get Key from Foursquare site. NearBy places Her

Abhishek Dubey 5 Nov 30, 2022
The Superhero app keeps track of the near real-time location of all the volunteers.

Superhero The Superhero app keeps track of the near real-time location of all the volunteers. The app sends requests for emergency tasks to nearby vol

CoronaSafe Network 4 May 3, 2022
Show weather data for the current location [Apollo Agriculture Interview Solution], for the Senior Android Engineer Role

Apollo Agriculture Android Take Home Assignment Writing Apollo Agriculture App using Android Architecture Components, in 100% Kotlin, using Android Je

Juma Allan 23 Nov 23, 2022
find the top coffee shop near by a given location

YelpCoffee&Tea 2 Different Activities (Screens): coffee shop List, coffee shop detail View Android app displays coffee shop locations in specified loc

null 0 Oct 31, 2021
Location Reminder App build as part of the udacity nanodegree program

Location Reminder a Location Reminder App with notifications that remind the user to do something when the user is at a specific location. built as pa

André Wagner 0 Dec 26, 2021
Simple android application that consumes Rick and Morty API to display characters,episodes,Location

Rick and Morty Compose An android app built using Kotlin that consumes Rick and

Michael Ndiritu 68 Nov 23, 2022
A simple xposed module that helps you fully control your location.

FuckLocation An simple xposed module that helps you fully control your location. 一个可以帮助你完全控制位置授权的模块 Currently, you may return custom location to speci

null 218 Dec 30, 2022
A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

A somewhat copy past of Jetbrain's code from the kotlin plugin repo to make it humanly possible to test Intellij IDEA kotlin plugins that work on kotlin

common sense OSS 0 Jan 20, 2022
A Kotlin Android library for heuristics evasion that prevents your code from being tested.

EvadeMe An Android library for heuristics evasion that prevents your code from being tested. User Instructions Add the maven repository to your projec

Chris Basinger 29 Dec 26, 2022
Library to use Kotlin Coroutines from Swift code in KMP apps

KMP-NativeCoroutines A library to use Kotlin Coroutines from Swift code in KMP apps. Flows Kotlin Create an extension property to expose the Flow as a

Rick Clephas 508 Jan 3, 2023