The optiGeofencing Android library enables your application to receive user location updates and geofence events with minimal effort in real time. Also we can use all the map util API's here to utilize all the map functionalies.
The library provides a high-level interface to perform different categories of map operations.
The optiGeofencingAndroid Framework supports Android API level 16 (Android 4.1) and above.
To begin, copy optiGeofencing module to your app
and add in build.gradle
dependencies section:
implementation project(path: ':optiGeofencing')
settings.gradle
include ':optiGeofencing'
change google playservice json settings in app/google-services.json
Amplify Android requires Java 8 features. Please add a compileOptions
block inside your app's build.gradle
, as below:
android {
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Features:
- supports Android-Q
- receive updates on background
- geofence updates (dwell, enter, exit)
- location updates
- configurable update intervals
- Find distance between source and destinations
- Show single or multiple markers
- Custom design markers
- Custom info window
- Draw polyline between two location points
-
Location permissions in AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
-
Google maps api key
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY</string>
- Create Receiver
class GeofenceIntentService : GeofenceIntentService() {
override fun onGeofence(geofence: Geofence) {
Log.v(GeoFenceIntentService::class.java.simpleName, "onGeofence $geofence")
}
}
-
Add receiver to your manifest
<service android:name=".kotlin.GeoFenceIntentService" android:permission="android.permission.BIND_JOB_SERVICE" />
val geofence = Geofence(
id = UUID.randomUUID().toString(),
latitude = 51.0899232,
longitude = 5.968358,
radius = 30.0,
title = "Germany",
message = "Entered Germany",
transitionType = GEOFENCE_TRANSITION_ENTER
)
Geofencer(this).addGeofence(geofence, GeoFenceIntentService::class.java) { /* successfully added geofence */ }
- Create Receiver
class LocationTrackerService : LocationTrackerUpdateIntentService() {
override fun onLocationResult(locationResult: LocationResult) {
Log.v(GeoFenceIntentService::class.java.simpleName, "onLocationResult $location")
}
}
-
Add receiver to manifest
<service android:name=".kotlin.LocationTrackerService" android:permission="android.permission.BIND_JOB_SERVICE" />
LocationTracker.requestLocationUpdates(this, LocationTrackerService::class.java)
- Stop tracking
LocationTracker.removeLocationUpdates(requireContext())
This library is licensed under the Apache 2.0 License.
We appreciate your feedback -- comments, questions, and bug reports. Please submit a GitHub issue, and we'll get back to you.