Snapp Location kit is a library that simplifies the process of working with Android location services. It provides a convenient and easy-to-use API for requesting and receiving location updates, handling permissions, checking location settings, and detecting mock locations. It also supports various location providers, such as fused location, GPS, network, and passive. Android Location Library is a useful tool for developers who want to build location-based applications on Android devices.
- Support Google location
- Support HMS (huawei) location
- Detect mock locations
- Check and resolve location setting
Client: Android
- Add dependency to build.gradle
dependencies {
implementation("io.github.snapp-incubator:location-kit:[latest-version]")
}
Then create an instance of SnappLocationProvider
val snappLocationProvider = LocationServiceBuilder(this)
.withUpdateInterval(10000L)
.withFastestUpdateInterval(10000L / 2)
.mockDistanceTrashHoldInMeter(1000)
.mockRealLocationTrashHold(20)
.freshLocationUpdateCount(2)
.forceUsingDeviceLocationSystemOnly(false)
.build()
Start getting locations
snappLocationProvider.startLocationUpdates()
Stop getting locations
snappLocationProvider.stopLocationUpdates()
Get one-time location
snappLocationProvider.getLocation { location -> }
Get location stream
snappLocationProvider.getLocationStream()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
if (location is NullLocation) {
location.exception?.let { exception ->
ResolvableApiExceptionHelper.startResolutionForResult(this, exception, 1001)
} ?: run {
Toast.makeText(this, "null location", Toast.LENGTH_SHORT).show()
}
} else {
// Do any stuff
showLocationDetails(location)
}
}
To check if the location is mocked
snappLocationProvider.getMockLocationStream()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { locationIsMock ->
// Do any stuff
}
Contributions are always welcome!
See contributing.md
for ways to get started.