Geolocation native Android library โก๏ธ
https://github.com/ionic-team/ion-android-geolocation.git
The ion-android-geolocation is a library built using Kotlin that provides geolocation features for Android applications.
The IONGLOCController class provides the main features of the Library, which are:
This library is used by the Geolocation Plugin for OutSystems' Cordova Plugin and Ionic's Capacitor Plugin.
In your app-level gradle file, import the ion-android-geolocation library like so:
dependencies {
implementation("io.ionic.libs:iongeolocation-android:2.2.0")
}
As mentioned before, the library offers the IONGLOCController class that provides the following methods to interact with:
suspend fun getCurrentPosition(
activity: Activity,
options: IONGLOCLocationOptions
): Result<IONGLOCLocationResult>
The method is composed of the following input parameters:
Activity from the app using the library to use when obtaining the location.IONGLOCLocationOptions with the options with which to make the location request with (e.g. timeout).Result containing either an object of type IONGLOCLocationResult, which includes the geolocation data (e.g. latitide, longitude), or an exception that should be handled by the caller app.
fun addWatch(
activity: Activity,
options: IONGLOCLocationOptions,
watchId: String
): Flow<Result<List<IONGLOCLocationResult>>>
The method is composed of the following input parameters:
Activity from the app using the library to use when obtaining the location updates.IONGLOCLocationOptions with the options with which to make the location updates request with (e.g. timeout).fun clearWatch(id: String): Boolean
The method is composed of the following input parameters:
watchId identigying the watch to remove.Common issues and solutions:
AndroidManifest.xmlIONGLOCLocationOptions.enableLocationManagerFallback to true - available since version 2.0.0watchPositionIONGLOCLocationOptions.interval parameter, introduced in version 2.1.0, and set it to below timeout, in order to try to receive a first location update before timing out.IONGLOCLocationOptions.timeout value, if your use case can wait for some time.IONGLOCLocationOptions.maximumAge to allow to retrieve an older location quickly for the first update.git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)ion-android-geolocation is available under the MIT license. See the LICENSE file for more info.