A powerful library for easy implementation of HMS Location Kit.

Overview

AdvancedLocation

Licence MIT Release

A powerful library for easy implementation of HMS Location Kit. 💙

  • Request location with couple lines of code (no more boilerplate)
  • Care more about battery consumption when requesting location
  • Reach location in the background with ease

Features

  • Auto Location Permission Request
  • Requesting Location Updates by caring battery consumption
  • Requesting Location Updates with custom values
  • Current Location (One time request)
  • Last Known Location (One time request)
  • Background Location Updates
  • Auto Activity Recognition Permission Request
  • Activity Type Recognition

Demo App

You can reach Demo app from here

Setup

⚠️ Please check your Android Studio version before proceed (Help > About) ⚠️

build.gradle (project) // Only for Android Studio Bumblebee | 2021.1.0 or lower
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
settings.gradle // Only for Android Studio Bumblebee | 2021.1.1 or newer
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
build.gradle (app)
dependencies {
    ...
    implementation 'com.github.talhaoz:advanced-location:1.1.1'
}
agconnect-services.json
Add agconnect-services.json file under app directory

Use

// Creates an AdvancedLocation object
val advancedLocation = AdvancedLocation() 
  • Request Location Updates

/**
*  @param activity is required to check for location permission
*  @param locationType can be HIGH_ACCURACY, EFFICIENT_POWER, LOW_POWER or PASSIVE
*  @param interval interval(refresh frequency) --> default value = 0L
*  @param resultListener returns an object of position(latitude,longitude)
*/
advancedLocation.requestLocationUpdates(
    this,
    LocationType.EFFICIENT_POWER,
    UpdateInterval.INTERVAL_15_SECONDS
) {
    Log.d(TAG, "Lat: ${it.latitude}\n Long: ${it.longitude}")
}
  • Request Location Updates with custom values

/**
*  @param activity is required to check for location permission
*  @param interval interval(refresh frequency) --> default value = 0L
*  @param smallestDisplacement(max difference between positions) --> default value = 0F
*  @param resultListener returns an object of position(latitude,longitude)
*/
advancedLocation.requestCustomLocationUpdates(
    this,
    interval = 20L,
    smallestDisplacement = 1F
) {
    Log.d(TAG, "Lat: ${it.latitude}\n Long: ${it.longitude}")
}
  • Remove Location Update request

advancedLocation.removeLocationUpdateRequest()
  • Current Location (One time request)

/**
*  @param activity is required for permission
*  @param resultListener returns the position(latitude,longitude)
*/
advancedLocation.getCurrentLocation(this) {
    Log.d(TAG, "Lat: ${it.latitude}\n Long: ${it.longitude}")
}
  • Last Known Location (One time request)

/**
*  @param activity is required in case initialization fails
*  @param taskListener returns the position(latitude,longitude) on success
*  or returns an exception on failure
*/
advancedLocation.getLastLocation(this) {
    val position = it.value
    Log.d(TAG, "Lat: ${position.latitude}\n Long: ${position.longitude}")
}
  • Background Location Updates

/**
*  Requests Location Updates by running a foreground service and stores them in the Room DB (including old locations)
*
*  @param activity is required for permission
*  @param notificationTitle is title for Notification that displayed along with foreground service (if Empty app name will be displayed)
*  @param notificationDescription is description for Notification that displayed along with foreground service(if Empty default desc will be displayed)
*  @param updateInterval location update refresh frequency (Default value = 5 mins)
*  @returns BackgroundLocationResult that accesses to RoomDB (only get)
*/
advancedLocation.startBackgroundLocationUpdates(
    this,
    "Advanced Location Demo",
    "Reaching your location in background..",
    UpdateInterval.INTERVAL_FIVE_MINUTES
).let {
    val list = it.getAllLocationUpdates()
    list?.forEach { location ->
        Log.d(TAG, "### Lat: ${location.latitude}\n Long: ${location.longitude}")
    }
}
  • Stop Background Location Updates

advancedLocation.stopBackgroundLocationUpdates()
  • Clear Stored Location Updates from DB

advancedLocation.clearLocationDB()
  • Activity Recognition

// Requests the current activity type and stores the result in the Room DB
advancedLocation.getActivityType(
    this
).let { activityTypeResult ->
    val activityType = activityTypeResult.getActivityType()
    activityType.let {
        Log.d(TAG, "Activity Type: ${it?.type}")
    }
}
  • Clear Stored Activity Type from DB

advancedLocation.clearActivityTypeDB()

License

MIT License

Copyright (c) 2022 Talha ÖZ

You might also like...
Lightning Dev Kit Android Demo Wallet

uMlando-wallet Lightning Dev Kit Android Demo Wallet This project uses a .aar package for the Android platforms that provide language bindings for the

Android barcode scanner with ML-Kit vision api
Android barcode scanner with ML-Kit vision api

MLBarcodeScanner A demo project to show how to implement barcode scanner using Google ML-Kit Vision api Supported barcode types 2D formats: QR Code, A

Project BlueWeather is an android app that lists the closest locations to you and shows the 7-day weather forecast for the location you select.
Project BlueWeather is an android app that lists the closest locations to you and shows the 7-day weather forecast for the location you select.

Project BLUEWEATHER Description Project BlueWeather is a weather forecast application for android. It lists the locations closest to you. It then prov

Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能
Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能

Location Location 是一个通过 Android 自带的 LocationManager 来实现的定位功能。 之所以写这个库的主要原因还需要从下面的场景说起:在开发某个App的过程当中,可能有个需求需要用到定位功能,但是又不那么重要; 这个时候如果选择使用第三方的定位服务,需要先去申请

Realtime SOS Android Application. Location (GPS + Cellular Network) tracing application by alerting guardians of the User.

WomenSaftey Women Safety Android Application: Realtime SOS Android Application. Designed a Location (GPS + Cellular Network) tracing application by al

This app to track realtime location

✨ hacktoberfest2021 💫 🌱 Contributing to hacktoberfest 2021 Welcome to hacktoberfest 2021 Public Repository. 👨🏻‍💻 A month-long celebration from Oc

A news app made using android studio in Java with features like favourite news, Location detector for local news, and especially made with HUAWEI APIs

HuaweiGlobalNewsApp A news app made using android studio in Java with features like favourite news, Location detector for local news, and especially m

Android application that implements location and network related Android APIs

Location and network data collection Location and network data collection with Android's telephonyManager class. Introduction Technologies Android's A

This Andoird project is about classifying garbage pictures using a CNN-based Tensorflowlite model and fetching location using GPS to mark its area on the map.
This Andoird project is about classifying garbage pictures using a CNN-based Tensorflowlite model and fetching location using GPS to mark its area on the map.

Grbage_Detector_And_Locator Description As per some of the recent reports published, in India, the pollution levels are increasing at a colossal pace

Releases(1.1.1)
Owner
Aggregate developers' contributions to the HMS ecosystem,and expect to promote communication among more HMS-loving individual developers
null
Google map location tracker uploading current to realtime database and displaying location information from firebase realtime.

WEEK-8-SQ009-ANDROID LOCATION - GROUP WORK (2) Problem Description Track your partner(s). Implementation 1: You are to build a map application to show

null 0 Mar 16, 2022
A Todo list app with location reminders that remind the user to do something when he reaches a specific location.

A Todo list app with location reminders that remind the user to do something when he reaches a specific location.

Virginia Redondo 0 Jan 6, 2022
Xposed module which will set location where you want without effect mock location.

GPS Setter Support/Discussion: XDA thread As most of GPS spoof app not working anymore coz some are old and some are not proper implement with current

Android1500 73 Dec 28, 2022
This application uses Google Play Services Vision library to scan barcodes. It uses Google's on device ML kit to scan for barcodes.

Barcode-Scanner This application showcases use of Google Play Services Vision library It uses Google's on device machine learning kit to scan for barc

Soumik 2 Apr 28, 2022
A Minecraft Kit API written in Kotlin

hglabor-kits Dependency The library is available on Maven Central, add the following dependencies: implementation("net.axay:hglabor-kits:$version") hg

Jakob K 8 Apr 8, 2022
Text Recognizer App Using the ML Kit

Features Detects text in images Using the ML Kit Text Recognition API Uses the CameraX to show a viewfinder and display the camera preview Provides a

krishna chaitanya 9 Nov 5, 2022
Native android application that scans for text in images. Uses ML kit under the hood.

Scannerate - Ad free Text Recognition Android application built using Kotlin to extract text from images. Uses Google's ML kit library under the hood.

null 24 Dec 1, 2022
WalletConnect Kit is the Swiss Army toolkit for WalletConnect!

WalletConnectKit WalletConnectKit is the Swiss Army toolkit for WalletConnect! It will allow you to connect your DApp with an Ethereum Wallet in a few

Pink Room 52 Nov 24, 2022
SmartLens uses Google's ML Kit for Barcode scanning, Face recognition, Text recognition, and Image labeling.

SmartLens SmartLens uses Google's ML Kit for Barcode scanning, Face recognition, Text recognition, and Image labeling. ?? Screen Shots ?? Features It

Prince Fahad 2 Sep 14, 2022
Face Detector Using Firebase ML Kit

Face Detector (Using Firebase ML Kit) Detects Facial Expression ------> Overlays

Sachin Kumar 1 Jan 4, 2022