Repository navigation
feat!: Android-only location button and getLocationButtonState() #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/RMET-5199/location-button
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,16 +52,35 @@ Read about [Setting Permissions](https://capacitorjs.com/docs/android/configurat | |
|
|
||
| ## Location Button | ||
|
|
||
| Importing `@capacitor/geolocation` registers `<os-location-button>`. The plugin | ||
| Importing `@capacitor/geolocation` registers `<os-location-button>` on Android. The plugin | ||
| includes the Native Islands runtime, so applications do not install it separately. | ||
|
|
||
| ```html | ||
| <os-location-button text-type="use-precise-location"></os-location-button> | ||
| ``` | ||
|
|
||
| On Android, the element renders a native button and emits `location-grant`, | ||
| `location-position`, and `location-error` DOM events. Browsers use | ||
| `navigator.geolocation`. Native iOS support is not currently provided. | ||
| The element shows the system location button on Android 17 and later, and Google's | ||
| compatibility button on older versions. It emits `location-grant`, `location-position`, and | ||
| `location-error` DOM events. On iOS and web it renders nothing. Call | ||
| [`getLocationButtonState()`](#getlocationbuttonstate) to hide the button or show your own control. | ||
|
|
||
| Attributes: `text-type` (`use-precise-location` by default, or `share-precise-location`, | ||
| `near-my-precise-location`, `near-your-precise-location`, `precise-location`, `none`), `timeout` | ||
| (5000 ms), `maximum-age` (3000 ms) and `enable-location-fallback` (`true`). The system translates | ||
| the label, so it can differ from your app's language. | ||
|
Comment on lines
+67
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a reminder that if you change the defaults in the TS code based on my other comment, change them here too. |
||
|
|
||
| To grant precise location only through the button, keep `ACCESS_COARSE_LOCATION` and declare | ||
| `ACCESS_FINE_LOCATION` with the `onlyForLocationButton` flag: | ||
|
|
||
| ```xml | ||
| <uses-permission | ||
| android:name="android.permission.ACCESS_FINE_LOCATION" | ||
| android:usesPermissionFlags="onlyForLocationButton" /> | ||
| ``` | ||
|
|
||
| On Android 17 and later, the regular API then gets approximate location until the button grants | ||
| precise location: after a request, `coarseLocation` is `granted` and `location` is `denied`. Older | ||
| versions ignore the flag. | ||
|
Comment on lines
+81
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't clear to me initially that "regular API" included request/check permissions and getting actual position. Added some code to the example app here to validate that it's just that. Maybe this phrase could be made a bit clearer? |
||
|
|
||
| Style the element with ordinary CSS. The icon can inherit `color` or use its | ||
| component-specific custom property: | ||
|
|
@@ -79,7 +98,8 @@ os-location-button { | |
| ``` | ||
|
|
||
| The native button supports opaque hexadecimal and RGB colors. Border width supports | ||
| `0px` through `3px`; the corner radius supports `0px` through `68px`. | ||
| `0px` through `3px`; the corner radius supports `0px` through `68px`. Android draws no button | ||
| smaller than 48 by 48 pixels. | ||
|
|
||
| ## API | ||
|
|
||
|
|
@@ -90,6 +110,7 @@ The native button supports opaque hexadecimal and RGB colors. Border width suppo | |
| * [`clearWatch(...)`](#clearwatch) | ||
| * [`checkPermissions()`](#checkpermissions) | ||
| * [`requestPermissions(...)`](#requestpermissions) | ||
| * [`getLocationButtonState()`](#getlocationbuttonstate) | ||
| * [Interfaces](#interfaces) | ||
| * [Type Aliases](#type-aliases) | ||
|
|
||
|
|
@@ -193,6 +214,23 @@ Not available on web. | |
| -------------------- | ||
|
|
||
|
|
||
| ### getLocationButtonState() | ||
|
|
||
| ```typescript | ||
| getLocationButtonState() => Promise<LocationButtonState> | ||
| ``` | ||
|
|
||
| Check which location button this device supports. | ||
|
|
||
| The button is Android only. Use this to hide it, or to show your own control instead. | ||
|
|
||
| **Returns:** <code>Promise<<a href="#locationbuttonstate">LocationButtonState</a>></code> | ||
|
|
||
| **Since:** 9.0.0 | ||
|
|
||
| -------------------- | ||
|
|
||
|
|
||
| ### Interfaces | ||
|
|
||
|
|
||
|
|
@@ -238,6 +276,13 @@ Not available on web. | |
| | **`permissions`** | <code>GeolocationPermissionType[]</code> | | ||
|
|
||
|
|
||
| #### LocationButtonState | ||
|
|
||
| | Prop | Type | Description | Since | | ||
| | ----------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | | ||
| | **`state`** | <code>'system' \| 'compat' \| 'unavailable'</code> | `system` on Android 17 and later, where the system draws the button. `compat` on older Android versions, which show Google's compatibility button. `unavailable` on iOS and web, where the `os-location-button` element renders nothing. | 9.0.0 | | ||
|
|
||
|
|
||
| ### Type Aliases | ||
|
|
||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed to be done in this PR, but I might do after this PR is merged -> We probably don't need the iOS version of the app anymore. I mean what it would verify is that the button doesn't render, but don't think that's really worth it having 10 or 20 more files in the "final" PR. We can at least check that it doesn't appear on web, which is good enough for me. But let me know if you agree / disagree. Might be thinking too much about small stuff here 😅 Maybe checking the visibility on iOS / web could be covered by a quick test? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,28 @@ export interface GeolocationPlugin { | |
| * @since 1.0.0 | ||
| */ | ||
| requestPermissions(permissions?: GeolocationPluginPermissions): Promise<PermissionStatus>; | ||
|
|
||
| /** | ||
| * Check which location button this device supports. | ||
| * | ||
| * The button is Android only. Use this to hide it, or to show your own control instead. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Use this to hide it" seems misleading, because it's not shown outside of Android. Is there any visual difference from hiding it based on |
||
| * | ||
| * @since 9.0.0 | ||
| */ | ||
| getLocationButtonState(): Promise<LocationButtonState>; | ||
| } | ||
|
|
||
| export interface LocationButtonState { | ||
| /** | ||
| * `system` on Android 17 and later, where the system draws the button. | ||
| * | ||
| * `compat` on older Android versions, which show Google's compatibility button. | ||
|
Comment on lines
+91
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth making the distinction that to comply with google play's location button requirements, you technically only need to use <os-location-button for Although, maybe that's better served in the plugin documentation in |
||
| * | ||
| * `unavailable` on iOS and web, where the `os-location-button` element renders nothing. | ||
| * | ||
| * @since 9.0.0 | ||
| */ | ||
| state: 'system' | 'compat' | 'unavailable'; | ||
| } | ||
|
|
||
| export interface ClearWatchOptions { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is documentation to show users how to declare the location button, it seems a bit confusing.