Simple library for reactive getting user locations
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
locgetter-sample
locgetter
.gitignore
LICENSE
README.md
bintray.gradle
build.gradle
deps.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

LocGetter

GitHub license _Download

Overview

Simple multithread-friendly library for getting latest user locations using RxJava 2.

Install

Gradle

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        jcenter()
    }
}

Step 2. Add the dependency

For Android studio 3.0

Recommended: This will use all libraries that you defined

dependencies {
    implementation 'io.reactivex.rxjava2:rxandroid:YOUR_RX_ANDROID_VERSION'
    implementation 'io.reactivex.rxjava2:rxjava:YOUR_RX_JAVA_2_VERSION'
    implementation 'com.google.android.gms:play-services-location:YOUR_GOOGLE_PLAY_VERSION'
    implementation ('codes.titanium:locgetter:1.1.2',{
        transitive = false
    })
}

Not recommended: This will use all dependencies from library, may increase apk size, increase methods count and lead to compile errors

dependencies {
    implementation 'codes.titanium:locgetter:1.1.2'
}

Basic Usage

Main features:

  • Getting updates of user locations
  • Getting latest saved user location
  • Getting current user location
  • Catching all errors connects to getting locations

All you need is to create LocationGetter instance using LocationGetterBuilder

 LocationGetter locationGetter = new LocationGetterBuilder(getApplicationContext())
            .build();

Optional you can add to builder:

  • Logger to get logs of everything happening inside LocationGetter
  • Accept mock locations behavior

Start getting locations using one of methods for e.g.

locationGetter.getLatestLocation()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(location -> {
                ((TextView) findViewById(R.id.locations_tv)).setText(location.toString());
            }, Throwable::printStackTrace);

More examples can be found in sample package with sample app.

Error handling

All exceptions are handled in library.

In case of no permissions -> user will be asked to give permissions, if user declines -> NoLocationPermission will be thrown

In case of turned off location -> user will be asked to turn it on, if user declines -> LocationSettingsException will be thrown

Accept mock locations behavior

By default mock locations are accepted. You can filter all mock locations that are received by location manager. Just set acceptMockLocations to false when you are building location getter.

In case if mock location will be received MockLocationException will be thrown with that mocked location and you can decide what to do with it.

Release notes

1.1.2

  • Extracted ConnectableActivity

1.1.1

  • Updated documentation
  • Fixed ConnectableActivity visibility

1.1.0

  • Major refactor
  • Removed a lot of redundant APIs
  • No more need of activity to handle exceptions
  • Optimizations
  • Feature - mock locations filter

1.0.3

  • Updated Readme
  • Updated dependencies bump

1.0.2

  • Fixed bug with retrolambda crash of onLocationError
  • Added some additional logging

1.0.0

  • Initial release