Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ Not available on web.

#### PositionOptions

| Prop | Type | Description | Default | Since |
| --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
| **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 7.1.0 of the plugin, it is also used to determine the interval of location updates for `watchPosition`. | <code>10000</code> | 1.0.0 |
| **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
| **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
| Prop | Type | Description | Default | Since |
| ---------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- |
| **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
| **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 7.1.0 of the plugin, it is also used to determine the interval of location updates for `watchPosition`. | <code>10000</code> | 1.0.0 |
| **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
| **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
| **`enableLocationFallback`** | <code>boolean</code> | This option applies to Android only. Whether to fall back to the Android framework's `LocationManager` in case Google Play Service's location settings checks fail. This can happen for multiple reasons - e.g. device has no Play Services or device has no network connection (Airplane Mode) If set to `false`, failures are propagated to the caller. Note that `LocationManager` may not be as effective as Google Play Services implementation. If the device's in airplane mode, only the GPS provider is used, which may take longer to return a location, depending on GPS signal. This means that to receive location in such circumstances, you may need to provide a higher timeout. | <code>true</code> | 8.0.0 |


#### ClearWatchOptions
Expand Down Expand Up @@ -244,3 +245,4 @@ The following table list all the plugin errors:
| OS-PLUG-GLOC-0014 | Android | Google Play Services error user resolvable. |
| OS-PLUG-GLOC-0015 | Android | Google Play Services error. |
| OS-PLUG-GLOC-0016 | Android | Location settings error. |
| OS-PLUG-GLOC-0017 | Android | Unable to retrieve location because device has both Network and Location turned off. |
14 changes: 8 additions & 6 deletions packages/capacitor-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ Not available on web.

#### PositionOptions

| Prop | Type | Description | Default | Since |
| --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
| **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 7.1.0 of the plugin, it is also used to determine the interval of location updates for `watchPosition`. | <code>10000</code> | 1.0.0 |
| **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
| **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
| Prop | Type | Description | Default | Since |
| ---------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- |
| **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
| **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 7.1.0 of the plugin, it is also used to determine the interval of location updates for `watchPosition`. | <code>10000</code> | 1.0.0 |
| **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
| **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
| **`enableLocationFallback`** | <code>boolean</code> | This option applies to Android only. Whether to fall back to the Android framework's `LocationManager` in case Google Play Service's location settings checks fail. This can happen for multiple reasons - e.g. device has no Play Services or device has no network connection (Airplane Mode) If set to `false`, failures are propagated to the caller. Note that `LocationManager` may not be as effective as Google Play Services implementation. If the device's in airplane mode, only the GPS provider is used, which may take longer to return a location, depending on GPS signal. This means that to receive location in such circumstances, you may need to provide a higher timeout. | <code>true</code> | 8.0.0 |


#### ClearWatchOptions
Expand Down Expand Up @@ -244,3 +245,4 @@ The following table list all the plugin errors:
| OS-PLUG-GLOC-0014 | Android | Google Play Services error user resolvable. |
| OS-PLUG-GLOC-0015 | Android | Google Play Services error. |
| OS-PLUG-GLOC-0016 | Android | Location settings error. |
| OS-PLUG-GLOC-0017 | Android | Unable to retrieve location because device has both Network and Location turned off. |
2 changes: 1 addition & 1 deletion packages/capacitor-plugin/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repositories {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation("io.ionic.libs:iongeolocation-android:1.0.0")
implementation("io.ionic.libs:iongeolocation-android:2.0.0")
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ object GeolocationErrors {
code = formatErrorCode(16),
message = "Location settings error."
)

val NETWORK_LOCATION_DISABLED_ERROR = ErrorInfo(
code = formatErrorCode(17),
message = "Unable to retrieve location because device has both Network and Location turned off."
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ class GeolocationPlugin : Plugin() {
}
}

this.controller = IONGLOCController(
LocationServices.getFusedLocationProviderClient(context),
activityLauncher
)

this.controller = IONGLOCController(context, activityLauncher)
}

override fun handleOnDestroy() {
Expand All @@ -82,7 +78,7 @@ class GeolocationPlugin : Plugin() {
* @param onLocationEnabled lambda function to use in case location services are enabled
*/
private fun checkLocationState(call: PluginCall, onLocationEnabled: () -> Unit) {
if (controller.areLocationServicesEnabled(context)) {
if (controller.areLocationServicesEnabled()) {
onLocationEnabled()
} else {
call.sendError(GeolocationErrors.LOCATION_DISABLED)
Expand Down Expand Up @@ -279,6 +275,9 @@ class GeolocationPlugin : Plugin() {
is IONGLOCException.IONGLOCSettingsException -> {
call.sendError(GeolocationErrors.LOCATION_SETTINGS_ERROR)
}
is IONGLOCException.IONGLOCLocationAndNetworkDisabledException -> {
call.sendError(GeolocationErrors.NETWORK_LOCATION_DISABLED_ERROR)
}
is IONGLOCException.IONGLOCInvalidTimeoutException -> {
call.sendError(GeolocationErrors.INVALID_TIMEOUT)
}
Expand Down Expand Up @@ -330,8 +329,15 @@ class GeolocationPlugin : Plugin() {
val maximumAge = call.getNumber("maximumAge", 0)
val enableHighAccuracy = call.getBoolean("enableHighAccuracy", false) ?: false
val minimumUpdateInterval = call.getNumber("minimumUpdateInterval", 5000)

val locationOptions = IONGLOCLocationOptions(timeout, maximumAge, enableHighAccuracy, minimumUpdateInterval)
val enableLocationFallback = call.getBoolean("enableLocationFallback", true) ?: true

val locationOptions = IONGLOCLocationOptions(
timeout,
maximumAge,
enableHighAccuracy,
enableLocationFallback,
minimumUpdateInterval
)

return locationOptions
}
Expand Down
15 changes: 15 additions & 0 deletions packages/capacitor-plugin/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ export interface PositionOptions {
* @since 6.1.0
*/
minimumUpdateInterval?: number;

/**
* This option applies to Android only.
*
* Whether to fall back to the Android framework's `LocationManager` in case Google Play Service's location settings checks fail.
* This can happen for multiple reasons - e.g. device has no Play Services or device has no network connection (Airplane Mode)
* If set to `false`, failures are propagated to the caller.
* Note that `LocationManager` may not be as effective as Google Play Services implementation.
* If the device's in airplane mode, only the GPS provider is used, which may take longer to return a location, depending on GPS signal.
* This means that to receive location in such circumstances, you may need to provide a higher timeout.
*
* @default true
* @since 8.0.0
*/
enableLocationFallback?: boolean;
}

export type WatchPositionCallback = (position: Position | null, err?: any) => void;
Expand Down
Loading