@capacitor/geolocation 8.0.0 → 8.2.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,10 +9,10 @@ Pod::Spec.new do |s|
9
9
  s.license = package['license']
10
10
  s.homepage = package['repository']['url']
11
11
  s.author = package['author']
12
- s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
12
+ s.source = { :git => package['repository']['url'], :tag => "v#{s.version}" }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'IONGeolocationLib', spec='2.0.0'
16
+ s.dependency 'IONGeolocationLib', '2.1.0'
17
17
  s.swift_version = '5.1'
18
18
  end
package/Package.swift CHANGED
@@ -11,7 +11,7 @@ let package = Package(
11
11
  ],
12
12
  dependencies: [
13
13
  .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
14
- .package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "2.0.0")
14
+ .package(url: "https://github.com/ionic-team/ion-ios-geolocation.git", from: "2.1.0")
15
15
  ],
16
16
  targets: [
17
17
  .target(
package/README.md CHANGED
@@ -159,10 +159,10 @@ Not available on web.
159
159
 
160
160
  #### Position
161
161
 
162
- | Prop | Type | Description | Since |
163
- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ----- |
164
- | **`timestamp`** | <code>number</code> | Creation timestamp for coords | 1.0.0 |
165
- | **`coords`** | <code>{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number \| null; altitude: number \| null; speed: number \| null; heading: number \| null; }</code> | The GPS coordinates along with the accuracy of the data | 1.0.0 |
162
+ | Prop | Type | Description | Since |
163
+ | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ----- |
164
+ | **`timestamp`** | <code>number</code> | Creation timestamp for coords | 1.0.0 |
165
+ | **`coords`** | <code>{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number \| null; altitude: number \| null; speed: number \| null; heading: number \| null; magneticHeading: number \| null; trueHeading: number \| null; headingAccuracy: number \| null; course: number \| null; }</code> | The GPS coordinates along with the accuracy of the data | 1.0.0 |
166
166
 
167
167
 
168
168
  #### PositionOptions
@@ -172,7 +172,7 @@ Not available on web.
172
172
  | **`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 |
173
173
  | **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. | <code>10000</code> | 1.0.0 |
174
174
  | **`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 |
175
- | **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for `watchPosition`. Not to be confused with `interval`. 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 |
175
+ | **`minimumUpdateInterval`** | <code>number</code> | The minimum update interval for `watchPosition`. Not to be confused with `interval`. 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 |
176
176
  | **`interval`** | <code>number</code> | Desired interval in milliseconds to receive location updates in `watchPosition`. For very low values of `interval` (a couple seconds or less), the platform may not guarantee timely location updates - they may take longer than specified. The platform may also be able to provide location updates faster than `interval`. You may use `minimumUpdateInterval` to control that behavior. For backwards compatiblity with version 7.1.x, if no value is passed, the default value of this parameter is that of `timeout`. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>`timeout`</code> | 8.0.0 |
177
177
  | **`enableLocationFallback`** | <code>boolean</code> | 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. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>true</code> | 8.0.0 |
178
178
 
@@ -1,4 +1,5 @@
1
1
  ext {
2
+ capacitorVersion = System.getenv('CAPACITOR_VERSION')
2
3
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
4
  androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
5
  androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
@@ -12,15 +13,26 @@ buildscript {
12
13
  repositories {
13
14
  google()
14
15
  mavenCentral()
16
+ maven {
17
+ url = "https://plugins.gradle.org/m2/"
18
+ }
15
19
  }
16
20
  dependencies {
17
21
  classpath 'com.android.tools.build:gradle:8.13.0'
18
22
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
23
+ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
24
+ classpath 'io.github.gradle-nexus:publish-plugin:1.3.0'
25
+ }
19
26
  }
20
27
  }
21
28
 
22
29
  apply plugin: 'com.android.library'
23
30
  apply plugin: 'kotlin-android'
31
+ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
32
+ apply plugin: 'io.github.gradle-nexus.publish-plugin'
33
+ apply from: file('../scripts/android/publish-root.gradle')
34
+ apply from: file('../scripts/android/publish-module.gradle')
35
+ }
24
36
 
25
37
  android {
26
38
  namespace = "com.capacitorjs.plugins.geolocation"
@@ -35,7 +47,7 @@ android {
35
47
  buildTypes {
36
48
  release {
37
49
  minifyEnabled false
38
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
50
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
39
51
  }
40
52
  }
41
53
  lintOptions {
@@ -45,6 +57,9 @@ android {
45
57
  sourceCompatibility JavaVersion.VERSION_21
46
58
  targetCompatibility JavaVersion.VERSION_21
47
59
  }
60
+ publishing {
61
+ singleVariant("release")
62
+ }
48
63
  }
49
64
 
50
65
  kotlin {
@@ -59,8 +74,14 @@ repositories {
59
74
 
60
75
  dependencies {
61
76
  implementation fileTree(dir: 'libs', include: ['*.jar'])
62
- implementation("io.ionic.libs:iongeolocation-android:2.1.0")
63
- implementation project(':capacitor-android')
77
+
78
+ if (System.getenv("CAP_PLUGIN_PUBLISH") == "true") {
79
+ implementation "com.capacitorjs:core:$capacitorVersion"
80
+ } else {
81
+ implementation project(':capacitor-android')
82
+ }
83
+
84
+ implementation("io.ionic.libs:iongeolocation-android:2.2.0")
64
85
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
65
86
 
66
87
  implementation 'com.google.code.gson:gson:2.13.2'
@@ -254,7 +254,11 @@ class GeolocationPlugin : Plugin() {
254
254
  put("altitude", locationResult.altitude)
255
255
  locationResult.altitudeAccuracy?.let { put("altitudeAccuracy", it) }
256
256
  put("speed", locationResult.speed)
257
- put("heading", locationResult.heading)
257
+ put("heading", if (locationResult.heading != -1f) locationResult.heading else null)
258
+ put("magneticHeading", locationResult.magneticHeading)
259
+ put("trueHeading", locationResult.trueHeading)
260
+ put("headingAccuracy", locationResult.headingAccuracy)
261
+ put("course", locationResult.course)
258
262
  }
259
263
  return JSObject().apply {
260
264
  put("timestamp", locationResult.timestamp)
package/dist/docs.json CHANGED
@@ -156,7 +156,7 @@
156
156
  ],
157
157
  "docs": "The GPS coordinates along with the accuracy of the data",
158
158
  "complexTypes": [],
159
- "type": "{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number | null | undefined; altitude: number | null; speed: number | null; heading: number | null; }"
159
+ "type": "{ latitude: number; longitude: number; accuracy: number; altitudeAccuracy: number | null | undefined; altitude: number | null; speed: number | null; heading: number | null; magneticHeading: number | null | undefined; trueHeading: number | null | undefined; headingAccuracy: number | null | undefined; course: number | null | undefined; }"
160
160
  }
161
161
  ]
162
162
  },
@@ -227,7 +227,7 @@
227
227
  "name": "since"
228
228
  }
229
229
  ],
230
- "docs": "The minumum update interval for `watchPosition`. Not to be confused with `interval`.\n\nIf location updates are available faster than this interval then an update\nwill only occur if the minimum update interval has expired since the last location update.\n\nThis parameter is only available for Android. It has no effect on iOS or Web platforms.",
230
+ "docs": "The minimum update interval for `watchPosition`. Not to be confused with `interval`.\n\nIf location updates are available faster than this interval then an update\nwill only occur if the minimum update interval has expired since the last location update.\n\nThis parameter is only available for Android. It has no effect on iOS or Web platforms.",
231
231
  "complexTypes": [],
232
232
  "type": "number | undefined"
233
233
  },
@@ -121,11 +121,47 @@ export interface Position {
121
121
  */
122
122
  speed: number | null;
123
123
  /**
124
- * The heading the user is facing (if available)
124
+ * The heading the user is facing (if available).
125
+ *
126
+ * Historically, this field returned the direction of travel (course) on iOS and Android.
127
+ * It now prioritizes the compass heading (true or magnetic) if available, falling back
128
+ * to the direction of travel (course).
125
129
  *
126
130
  * @since 1.0.0
127
131
  */
128
132
  heading: number | null;
133
+ /**
134
+ * The heading (measured in degrees) relative to magnetic north.
135
+ *
136
+ * Only available when using `watchPosition`.
137
+ *
138
+ * @since 8.2.0
139
+ */
140
+ magneticHeading: number | null | undefined;
141
+ /**
142
+ * The heading (measured in degrees) relative to true north.
143
+ *
144
+ * Only available when using `watchPosition`.
145
+ *
146
+ * @since 8.2.0
147
+ */
148
+ trueHeading: number | null | undefined;
149
+ /**
150
+ * The maximum deviation (measured in degrees) between the reported heading and the true geomagnetic heading.
151
+ *
152
+ * Only available when using `watchPosition`.
153
+ *
154
+ * @since 8.2.0
155
+ */
156
+ headingAccuracy: number | null | undefined;
157
+ /**
158
+ * The direction in which the device is travelling, measured in degrees and relative to due north.
159
+ *
160
+ * Only available when using `watchPosition`.
161
+ *
162
+ * @since 8.2.0
163
+ */
164
+ course: number | null | undefined;
129
165
  };
130
166
  }
131
167
  export interface PositionOptions {
@@ -154,7 +190,7 @@ export interface PositionOptions {
154
190
  */
155
191
  maximumAge?: number;
156
192
  /**
157
- * The minumum update interval for `watchPosition`. Not to be confused with `interval`.
193
+ * The minimum update interval for `watchPosition`. Not to be confused with `interval`.
158
194
  *
159
195
  * If location updates are available faster than this interval then an update
160
196
  * will only occur if the minimum update interval has expired since the last location update.
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport type CallbackID = string;\n\nexport interface PermissionStatus {\n /**\n * Permission state for location alias.\n *\n * On Android it requests/checks both ACCESS_COARSE_LOCATION and\n * ACCESS_FINE_LOCATION permissions.\n *\n * On iOS and web it requests/checks location permission.\n *\n * @since 1.0.0\n */\n location: PermissionState;\n\n /**\n * Permission state for coarseLocation alias.\n *\n * On Android it requests/checks ACCESS_COARSE_LOCATION.\n *\n * On Android 12+, users can choose between Approximate location (ACCESS_COARSE_LOCATION) or\n * Precise location (ACCESS_FINE_LOCATION), so this alias can be used if the app doesn't\n * need high accuracy.\n *\n * On iOS and web it will have the same value as location alias.\n *\n * @since 1.2.0\n */\n coarseLocation: PermissionState;\n}\n\nexport type GeolocationPermissionType = 'location' | 'coarseLocation';\n\nexport interface GeolocationPluginPermissions {\n permissions: GeolocationPermissionType[];\n}\n\nexport interface GeolocationPlugin {\n /**\n * Get the current GPS location of the device\n *\n * @since 1.0.0\n */\n getCurrentPosition(options?: PositionOptions): Promise<Position>;\n\n /**\n * Set up a watch for location changes. Note that watching for location changes\n * can consume a large amount of energy. Be smart about listening only when you need to.\n *\n * @since 1.0.0\n */\n watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID>;\n\n /**\n * Clear a given watch\n *\n * @since 1.0.0\n */\n clearWatch(options: ClearWatchOptions): Promise<void>;\n\n /**\n * Check location permissions. Will throw if system location services are disabled.\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request location permissions. Will throw if system location services are disabled.\n *\n * Not available on web.\n *\n * @since 1.0.0\n */\n requestPermissions(permissions?: GeolocationPluginPermissions): Promise<PermissionStatus>;\n}\n\nexport interface ClearWatchOptions {\n id: CallbackID;\n}\n\nexport interface Position {\n /**\n * Creation timestamp for coords\n *\n * @since 1.0.0\n */\n timestamp: number;\n\n /**\n * The GPS coordinates along with the accuracy of the data\n *\n * @since 1.0.0\n */\n coords: {\n /**\n * Latitude in decimal degrees\n *\n * @since 1.0.0\n */\n latitude: number;\n\n /**\n * longitude in decimal degrees\n *\n * @since 1.0.0\n */\n longitude: number;\n\n /**\n * Accuracy level of the latitude and longitude coordinates in meters\n *\n * @since 1.0.0\n */\n accuracy: number;\n\n /**\n * Accuracy level of the altitude coordinate in meters, if available.\n *\n * Available on all iOS versions and on Android 8.0+.\n *\n * @since 1.0.0\n */\n altitudeAccuracy: number | null | undefined;\n\n /**\n * The altitude the user is at (if available)\n *\n * @since 1.0.0\n */\n altitude: number | null;\n\n /**\n * The speed the user is traveling (if available)\n *\n * @since 1.0.0\n */\n speed: number | null;\n\n /**\n * The heading the user is facing (if available)\n *\n * @since 1.0.0\n */\n heading: number | null;\n };\n}\n\nexport interface PositionOptions {\n /**\n * High accuracy mode (such as GPS, if available)\n *\n * On Android 12+ devices it will be ignored if users didn't grant\n * ACCESS_FINE_LOCATION permissions (can be checked with location alias).\n *\n * @default false\n * @since 1.0.0\n */\n enableHighAccuracy?: boolean;\n\n /**\n * The maximum wait time in milliseconds for location updates.\n *\n * @default 10000\n * @since 1.0.0\n */\n timeout?: number;\n\n /**\n * The maximum age in milliseconds of a possible cached position that is acceptable to return\n *\n * @default 0\n * @since 1.0.0\n */\n maximumAge?: number;\n\n /**\n * The minumum update interval for `watchPosition`. Not to be confused with `interval`.\n *\n * If location updates are available faster than this interval then an update\n * will only occur if the minimum update interval has expired since the last location update.\n *\n * This parameter is only available for Android. It has no effect on iOS or Web platforms.\n *\n * @default 5000\n * @since 6.1.0\n */\n minimumUpdateInterval?: number;\n\n /**\n * Desired interval in milliseconds to receive location updates in `watchPosition`.\n *\n * For very low values of `interval` (a couple seconds or less),\n * the platform may not guarantee timely location updates - they may take longer than specified.\n * The platform may also be able to provide location updates faster than `interval`.\n * You may use `minimumUpdateInterval` to control that behavior.\n *\n * For backwards compatiblity with version 7.1.x, if no value is passed,\n * the default value of this parameter is that of `timeout`.\n *\n * This parameter is only available for Android. It has no effect on iOS or Web platforms.\n *\n * @default `timeout`\n * @since 8.0.0\n */\n interval?: number;\n\n /**\n * Whether to fall back to the Android framework's `LocationManager` in case Google Play Service's location settings checks fail.\n * This can happen for multiple reasons - e.g. device has no Play Services or device has no network connection (Airplane Mode)\n * If set to `false`, failures are propagated to the caller.\n * Note that `LocationManager` may not be as effective as Google Play Services implementation.\n * 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.\n * This means that to receive location in such circumstances, you may need to provide a higher timeout.\n *\n * This parameter is only available for Android. It has no effect on iOS or Web platforms.\n *\n * @default true\n * @since 8.0.0\n */\n enableLocationFallback?: boolean;\n}\n\nexport type WatchPositionCallback = (position: Position | null, err?: any) => void;\n\n/**\n * @deprecated Use `PositionOptions`.\n * @since 1.0.0\n */\nexport type GeolocationOptions = PositionOptions;\n\n/**\n * @deprecated Use `WatchPositionCallback`.\n * @since 1.0.0\n */\nexport type GeolocationWatchCallback = WatchPositionCallback;\n\n/**\n * @deprecated Use `Position`.\n * @since 1.0.0\n */\nexport type GeolocationPosition = Position;\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionState } from '@capacitor/core';\n\nexport type CallbackID = string;\n\nexport interface PermissionStatus {\n /**\n * Permission state for location alias.\n *\n * On Android it requests/checks both ACCESS_COARSE_LOCATION and\n * ACCESS_FINE_LOCATION permissions.\n *\n * On iOS and web it requests/checks location permission.\n *\n * @since 1.0.0\n */\n location: PermissionState;\n\n /**\n * Permission state for coarseLocation alias.\n *\n * On Android it requests/checks ACCESS_COARSE_LOCATION.\n *\n * On Android 12+, users can choose between Approximate location (ACCESS_COARSE_LOCATION) or\n * Precise location (ACCESS_FINE_LOCATION), so this alias can be used if the app doesn't\n * need high accuracy.\n *\n * On iOS and web it will have the same value as location alias.\n *\n * @since 1.2.0\n */\n coarseLocation: PermissionState;\n}\n\nexport type GeolocationPermissionType = 'location' | 'coarseLocation';\n\nexport interface GeolocationPluginPermissions {\n permissions: GeolocationPermissionType[];\n}\n\nexport interface GeolocationPlugin {\n /**\n * Get the current GPS location of the device\n *\n * @since 1.0.0\n */\n getCurrentPosition(options?: PositionOptions): Promise<Position>;\n\n /**\n * Set up a watch for location changes. Note that watching for location changes\n * can consume a large amount of energy. Be smart about listening only when you need to.\n *\n * @since 1.0.0\n */\n watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID>;\n\n /**\n * Clear a given watch\n *\n * @since 1.0.0\n */\n clearWatch(options: ClearWatchOptions): Promise<void>;\n\n /**\n * Check location permissions. Will throw if system location services are disabled.\n *\n * @since 1.0.0\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request location permissions. Will throw if system location services are disabled.\n *\n * Not available on web.\n *\n * @since 1.0.0\n */\n requestPermissions(permissions?: GeolocationPluginPermissions): Promise<PermissionStatus>;\n}\n\nexport interface ClearWatchOptions {\n id: CallbackID;\n}\n\nexport interface Position {\n /**\n * Creation timestamp for coords\n *\n * @since 1.0.0\n */\n timestamp: number;\n\n /**\n * The GPS coordinates along with the accuracy of the data\n *\n * @since 1.0.0\n */\n coords: {\n /**\n * Latitude in decimal degrees\n *\n * @since 1.0.0\n */\n latitude: number;\n\n /**\n * longitude in decimal degrees\n *\n * @since 1.0.0\n */\n longitude: number;\n\n /**\n * Accuracy level of the latitude and longitude coordinates in meters\n *\n * @since 1.0.0\n */\n accuracy: number;\n\n /**\n * Accuracy level of the altitude coordinate in meters, if available.\n *\n * Available on all iOS versions and on Android 8.0+.\n *\n * @since 1.0.0\n */\n altitudeAccuracy: number | null | undefined;\n\n /**\n * The altitude the user is at (if available)\n *\n * @since 1.0.0\n */\n altitude: number | null;\n\n /**\n * The speed the user is traveling (if available)\n *\n * @since 1.0.0\n */\n speed: number | null;\n\n /**\n * The heading the user is facing (if available).\n *\n * Historically, this field returned the direction of travel (course) on iOS and Android.\n * It now prioritizes the compass heading (true or magnetic) if available, falling back\n * to the direction of travel (course).\n *\n * @since 1.0.0\n */\n heading: number | null;\n\n /**\n * The heading (measured in degrees) relative to magnetic north.\n *\n * Only available when using `watchPosition`.\n *\n * @since 8.2.0\n */\n magneticHeading: number | null | undefined;\n\n /**\n * The heading (measured in degrees) relative to true north.\n *\n * Only available when using `watchPosition`.\n *\n * @since 8.2.0\n */\n trueHeading: number | null | undefined;\n\n /**\n * The maximum deviation (measured in degrees) between the reported heading and the true geomagnetic heading.\n *\n * Only available when using `watchPosition`.\n *\n * @since 8.2.0\n */\n headingAccuracy: number | null | undefined;\n\n /**\n * The direction in which the device is travelling, measured in degrees and relative to due north.\n *\n * Only available when using `watchPosition`.\n *\n * @since 8.2.0\n */\n course: number | null | undefined;\n };\n}\n\nexport interface PositionOptions {\n /**\n * High accuracy mode (such as GPS, if available)\n *\n * On Android 12+ devices it will be ignored if users didn't grant\n * ACCESS_FINE_LOCATION permissions (can be checked with location alias).\n *\n * @default false\n * @since 1.0.0\n */\n enableHighAccuracy?: boolean;\n\n /**\n * The maximum wait time in milliseconds for location updates.\n *\n * @default 10000\n * @since 1.0.0\n */\n timeout?: number;\n\n /**\n * The maximum age in milliseconds of a possible cached position that is acceptable to return\n *\n * @default 0\n * @since 1.0.0\n */\n maximumAge?: number;\n\n /**\n * The minimum update interval for `watchPosition`. Not to be confused with `interval`.\n *\n * If location updates are available faster than this interval then an update\n * will only occur if the minimum update interval has expired since the last location update.\n *\n * This parameter is only available for Android. It has no effect on iOS or Web platforms.\n *\n * @default 5000\n * @since 6.1.0\n */\n minimumUpdateInterval?: number;\n\n /**\n * Desired interval in milliseconds to receive location updates in `watchPosition`.\n *\n * For very low values of `interval` (a couple seconds or less),\n * the platform may not guarantee timely location updates - they may take longer than specified.\n * The platform may also be able to provide location updates faster than `interval`.\n * You may use `minimumUpdateInterval` to control that behavior.\n *\n * For backwards compatiblity with version 7.1.x, if no value is passed,\n * the default value of this parameter is that of `timeout`.\n *\n * This parameter is only available for Android. It has no effect on iOS or Web platforms.\n *\n * @default `timeout`\n * @since 8.0.0\n */\n interval?: number;\n\n /**\n * Whether to fall back to the Android framework's `LocationManager` in case Google Play Service's location settings checks fail.\n * This can happen for multiple reasons - e.g. device has no Play Services or device has no network connection (Airplane Mode)\n * If set to `false`, failures are propagated to the caller.\n * Note that `LocationManager` may not be as effective as Google Play Services implementation.\n * 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.\n * This means that to receive location in such circumstances, you may need to provide a higher timeout.\n *\n * This parameter is only available for Android. It has no effect on iOS or Web platforms.\n *\n * @default true\n * @since 8.0.0\n */\n enableLocationFallback?: boolean;\n}\n\nexport type WatchPositionCallback = (position: Position | null, err?: any) => void;\n\n/**\n * @deprecated Use `PositionOptions`.\n * @since 1.0.0\n */\nexport type GeolocationOptions = PositionOptions;\n\n/**\n * @deprecated Use `WatchPositionCallback`.\n * @since 1.0.0\n */\nexport type GeolocationWatchCallback = WatchPositionCallback;\n\n/**\n * @deprecated Use `Position`.\n * @since 1.0.0\n */\nexport type GeolocationPosition = Position;\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { CallbackID, GeolocationPlugin, PermissionStatus, Position, PositionOptions, WatchPositionCallback } from './definitions';
3
3
  export declare class GeolocationWeb extends WebPlugin implements GeolocationPlugin {
4
+ private latestOrientation;
5
+ constructor();
6
+ private updateOrientation;
7
+ private augmentPosition;
4
8
  getCurrentPosition(options?: PositionOptions): Promise<Position>;
5
9
  watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID>;
6
10
  clearWatch(options: {
package/dist/esm/web.js CHANGED
@@ -1,9 +1,69 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  export class GeolocationWeb extends WebPlugin {
3
+ constructor() {
4
+ super();
5
+ this.latestOrientation = null;
6
+ if (typeof window !== 'undefined') {
7
+ const win = window;
8
+ if ('ondeviceorientationabsolute' in win) {
9
+ win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);
10
+ }
11
+ else if ('ondeviceorientation' in win) {
12
+ win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);
13
+ }
14
+ }
15
+ }
16
+ updateOrientation(event, isAbsolute) {
17
+ let trueHeading = null;
18
+ let magneticHeading = null;
19
+ let headingAccuracy = null;
20
+ if (isAbsolute && event.alpha !== null) {
21
+ trueHeading = (360 - event.alpha) % 360;
22
+ }
23
+ else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {
24
+ magneticHeading = event.webkitCompassHeading;
25
+ headingAccuracy = event.webkitCompassAccuracy;
26
+ }
27
+ else if (event.alpha !== null && event.absolute === true) {
28
+ trueHeading = (360 - event.alpha) % 360;
29
+ }
30
+ else if (event.alpha !== null) {
31
+ magneticHeading = (360 - event.alpha) % 360;
32
+ }
33
+ if (trueHeading !== null || magneticHeading !== null) {
34
+ this.latestOrientation = {
35
+ trueHeading,
36
+ magneticHeading,
37
+ headingAccuracy,
38
+ };
39
+ }
40
+ }
41
+ augmentPosition(pos, isWatch = false) {
42
+ var _a, _b, _c, _d, _e, _f, _g;
43
+ const coords = pos.coords;
44
+ const orientation = isWatch ? this.latestOrientation : null;
45
+ const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;
46
+ return {
47
+ timestamp: pos.timestamp,
48
+ coords: {
49
+ latitude: coords.latitude,
50
+ longitude: coords.longitude,
51
+ accuracy: coords.accuracy,
52
+ altitude: coords.altitude,
53
+ altitudeAccuracy: coords.altitudeAccuracy,
54
+ speed: coords.speed,
55
+ heading: heading,
56
+ magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
57
+ trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
58
+ headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
59
+ course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,
60
+ },
61
+ };
62
+ }
3
63
  async getCurrentPosition(options) {
4
64
  return new Promise((resolve, reject) => {
5
65
  navigator.geolocation.getCurrentPosition((pos) => {
6
- resolve(pos);
66
+ resolve(this.augmentPosition(pos, false));
7
67
  }, (err) => {
8
68
  reject(err);
9
69
  }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));
@@ -11,7 +71,7 @@ export class GeolocationWeb extends WebPlugin {
11
71
  }
12
72
  async watchPosition(options, callback) {
13
73
  const id = navigator.geolocation.watchPosition((pos) => {
14
- callback(pos);
74
+ callback(this.augmentPosition(pos, true));
15
75
  }, (err) => {
16
76
  callback(null, err);
17
77
  }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,cAAe,SAAQ,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MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YACnD,IAAI,EAAE,aAAa;SACpB,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF;AAED,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CallbackID,\n GeolocationPlugin,\n PermissionStatus,\n Position,\n PositionOptions,\n WatchPositionCallback,\n} from './definitions';\n\nexport class GeolocationWeb extends WebPlugin implements GeolocationPlugin {\n async getCurrentPosition(options?: PositionOptions): Promise<Position> {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(\n (pos) => {\n resolve(pos);\n },\n (err) => {\n reject(err);\n },\n {\n enableHighAccuracy: false,\n timeout: 10000,\n maximumAge: 0,\n ...options,\n },\n );\n });\n }\n\n async watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID> {\n const id = navigator.geolocation.watchPosition(\n (pos) => {\n callback(pos);\n },\n (err) => {\n callback(null, err);\n },\n {\n enableHighAccuracy: false,\n timeout: 10000,\n maximumAge: 0,\n minimumUpdateInterval: 5000,\n ...options,\n },\n );\n\n return `${id}`;\n }\n\n async clearWatch(options: { id: string }): Promise<void> {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n\nconst Geolocation = new GeolocationWeb();\n\nexport { Geolocation };\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAO3C;QACE,KAAK,EAAE,CAAC;QAPF,sBAAiB,GAId,IAAI,CAAC;QAId,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,GAAG,GAAG,MAAa,CAAC;YAC1B,IAAI,6BAA6B,IAAI,GAAG,EAAE,CAAC;gBACzC,GAAG,CAAC,gBAAgB,CAAC,2BAA2B,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;YAC/G,CAAC;iBAAM,IAAI,qBAAqB,IAAI,GAAG,EAAE,CAAC;gBACxC,GAAG,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,CAAC,KAAU,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;YACxG,CAAC;QACH,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,KAAU,EAAE,UAAmB;QACvD,IAAI,WAAW,GAAkB,IAAI,CAAC;QACtC,IAAI,eAAe,GAAkB,IAAI,CAAC;QAC1C,IAAI,eAAe,GAAkB,IAAI,CAAC;QAE1C,IAAI,UAAU,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YACvC,WAAW,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;QAC1C,CAAC;aAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,SAAS,IAAI,KAAK,CAAC,oBAAoB,KAAK,IAAI,EAAE,CAAC;YAC3F,eAAe,GA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AAE,EAAE;YACN,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC,kBAEC,kBAAkB,EAAE,KAAK,EACzB,OAAO,EAAE,KAAK,EACd,UAAU,EAAE,CAAC,EACb,qBAAqB,EAAE,IAAI,IACxB,OAAO,EAEb,CAAC;QAEF,OAAO,GAAG,EAAE,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAuB;QACtC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;YAC/D,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC;QAC1E,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YACnD,IAAI,EAAE,aAAa;SACpB,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;CACF;AAED,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CallbackID,\n GeolocationPlugin,\n PermissionStatus,\n Position,\n PositionOptions,\n WatchPositionCallback,\n} from './definitions';\n\nexport class GeolocationWeb extends WebPlugin implements GeolocationPlugin {\n private latestOrientation: {\n magneticHeading: number | null;\n trueHeading: number | null;\n headingAccuracy: number | null;\n } | null = null;\n\n constructor() {\n super();\n if (typeof window !== 'undefined') {\n const win = window as any;\n if ('ondeviceorientationabsolute' in win) {\n win.addEventListener('deviceorientationabsolute', (event: any) => this.updateOrientation(event, true), true);\n } else if ('ondeviceorientation' in win) {\n win.addEventListener('deviceorientation', (event: any) => this.updateOrientation(event, false), true);\n }\n }\n }\n\n private updateOrientation(event: any, isAbsolute: boolean) {\n let trueHeading: number | null = null;\n let magneticHeading: number | null = null;\n let headingAccuracy: number | null = null;\n\n if (isAbsolute && event.alpha !== null) {\n trueHeading = (360 - event.alpha) % 360;\n } else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {\n magneticHeading = event.webkitCompassHeading;\n headingAccuracy = event.webkitCompassAccuracy;\n } else if (event.alpha !== null && event.absolute === true) {\n trueHeading = (360 - event.alpha) % 360;\n } else if (event.alpha !== null) {\n magneticHeading = (360 - event.alpha) % 360;\n }\n\n if (trueHeading !== null || magneticHeading !== null) {\n this.latestOrientation = {\n trueHeading,\n magneticHeading,\n headingAccuracy,\n };\n }\n }\n\n private augmentPosition(pos: globalThis.GeolocationPosition, isWatch = false): Position {\n const coords = pos.coords;\n const orientation = isWatch ? this.latestOrientation : null;\n\n const heading =\n orientation?.trueHeading ?? orientation?.magneticHeading ?? (isWatch ? coords.heading : null) ?? null;\n\n return {\n timestamp: pos.timestamp,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: coords.altitude,\n altitudeAccuracy: (coords as any).altitudeAccuracy,\n speed: coords.speed,\n heading: heading,\n magneticHeading: orientation?.magneticHeading ?? null,\n trueHeading: orientation?.trueHeading ?? null,\n headingAccuracy: orientation?.headingAccuracy ?? null,\n course: (isWatch ? coords.heading : null) ?? null,\n },\n };\n }\n\n async getCurrentPosition(options?: PositionOptions): Promise<Position> {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(\n (pos) => {\n resolve(this.augmentPosition(pos, false));\n },\n (err) => {\n reject(err);\n },\n {\n enableHighAccuracy: false,\n timeout: 10000,\n maximumAge: 0,\n ...options,\n },\n );\n });\n }\n\n async watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID> {\n const id = navigator.geolocation.watchPosition(\n (pos) => {\n callback(this.augmentPosition(pos, true));\n },\n (err) => {\n callback(null, err);\n },\n {\n enableHighAccuracy: false,\n timeout: 10000,\n maximumAge: 0,\n minimumUpdateInterval: 5000,\n ...options,\n },\n );\n\n return `${id}`;\n }\n\n async clearWatch(options: { id: string }): Promise<void> {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n\nconst Geolocation = new GeolocationWeb();\n\nexport { Geolocation };\n"]}
@@ -9,10 +9,70 @@ const Geolocation = core.registerPlugin('Geolocation', {
9
9
  synapse.exposeSynapse();
10
10
 
11
11
  class GeolocationWeb extends core.WebPlugin {
12
+ constructor() {
13
+ super();
14
+ this.latestOrientation = null;
15
+ if (typeof window !== 'undefined') {
16
+ const win = window;
17
+ if ('ondeviceorientationabsolute' in win) {
18
+ win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);
19
+ }
20
+ else if ('ondeviceorientation' in win) {
21
+ win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);
22
+ }
23
+ }
24
+ }
25
+ updateOrientation(event, isAbsolute) {
26
+ let trueHeading = null;
27
+ let magneticHeading = null;
28
+ let headingAccuracy = null;
29
+ if (isAbsolute && event.alpha !== null) {
30
+ trueHeading = (360 - event.alpha) % 360;
31
+ }
32
+ else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {
33
+ magneticHeading = event.webkitCompassHeading;
34
+ headingAccuracy = event.webkitCompassAccuracy;
35
+ }
36
+ else if (event.alpha !== null && event.absolute === true) {
37
+ trueHeading = (360 - event.alpha) % 360;
38
+ }
39
+ else if (event.alpha !== null) {
40
+ magneticHeading = (360 - event.alpha) % 360;
41
+ }
42
+ if (trueHeading !== null || magneticHeading !== null) {
43
+ this.latestOrientation = {
44
+ trueHeading,
45
+ magneticHeading,
46
+ headingAccuracy,
47
+ };
48
+ }
49
+ }
50
+ augmentPosition(pos, isWatch = false) {
51
+ var _a, _b, _c, _d, _e, _f, _g;
52
+ const coords = pos.coords;
53
+ const orientation = isWatch ? this.latestOrientation : null;
54
+ const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;
55
+ return {
56
+ timestamp: pos.timestamp,
57
+ coords: {
58
+ latitude: coords.latitude,
59
+ longitude: coords.longitude,
60
+ accuracy: coords.accuracy,
61
+ altitude: coords.altitude,
62
+ altitudeAccuracy: coords.altitudeAccuracy,
63
+ speed: coords.speed,
64
+ heading: heading,
65
+ magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
66
+ trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
67
+ headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
68
+ course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,
69
+ },
70
+ };
71
+ }
12
72
  async getCurrentPosition(options) {
13
73
  return new Promise((resolve, reject) => {
14
74
  navigator.geolocation.getCurrentPosition((pos) => {
15
- resolve(pos);
75
+ resolve(this.augmentPosition(pos, false));
16
76
  }, (err) => {
17
77
  reject(err);
18
78
  }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));
@@ -20,7 +80,7 @@ class GeolocationWeb extends core.WebPlugin {
20
80
  }
21
81
  async watchPosition(options, callback) {
22
82
  const id = navigator.geolocation.watchPosition((pos) => {
23
- callback(pos);
83
+ callback(this.augmentPosition(pos, true));
24
84
  }, (err) => {
25
85
  callback(null, err);
26
86
  }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(pos);\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(pos);\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"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Q,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AACtB,IAAI;AACJ,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;AAC9B,QAAQ,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClE,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;AACxE,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;AACnF,QAAQ;AACR,QAAQ,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;AAC7D,YAAY,IAAI,EAAE,aAAa;AAC/B,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE;AAC/E,IAAI;AACJ,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;AACoB,IAAI,cAAc;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n constructor() {\n super();\n this.latestOrientation = null;\n if (typeof window !== 'undefined') {\n const win = window;\n if ('ondeviceorientationabsolute' in win) {\n win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);\n }\n else if ('ondeviceorientation' in win) {\n win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);\n }\n }\n }\n updateOrientation(event, isAbsolute) {\n let trueHeading = null;\n let magneticHeading = null;\n let headingAccuracy = null;\n if (isAbsolute && event.alpha !== null) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {\n magneticHeading = event.webkitCompassHeading;\n headingAccuracy = event.webkitCompassAccuracy;\n }\n else if (event.alpha !== null && event.absolute === true) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.alpha !== null) {\n magneticHeading = (360 - event.alpha) % 360;\n }\n if (trueHeading !== null || magneticHeading !== null) {\n this.latestOrientation = {\n trueHeading,\n magneticHeading,\n headingAccuracy,\n };\n }\n }\n augmentPosition(pos, isWatch = false) {\n var _a, _b, _c, _d, _e, _f, _g;\n const coords = pos.coords;\n const orientation = isWatch ? this.latestOrientation : null;\n const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;\n return {\n timestamp: pos.timestamp,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: coords.altitude,\n altitudeAccuracy: coords.altitudeAccuracy,\n speed: coords.speed,\n heading: heading,\n magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,\n trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,\n headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,\n course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,\n },\n };\n }\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(this.augmentPosition(pos, false));\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(this.augmentPosition(pos, true));\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","exposeSynapse","WebPlugin"],"mappings":";;;;;AAEK,MAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAClE,CAAC;AACDC,qBAAa,EAAE;;ACJR,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf,QAAQ,IAAI,CAAC,iBAAiB,GAAG,IAAI;AACrC,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;AAC3C,YAAY,MAAM,GAAG,GAAG,MAAM;AAC9B,YAAY,IAAI,6BAA6B,IAAI,GAAG,EAAE;AACtD,gBAAgB,GAAG,CAAC,gBAAgB,CAAC,2BAA2B,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,E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,IAAI;AACJ;AACoB,IAAI,cAAc;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -7,10 +7,70 @@ var capacitorGeolocationPluginCapacitor = (function (exports, core, synapse) {
7
7
  synapse.exposeSynapse();
8
8
 
9
9
  class GeolocationWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super();
12
+ this.latestOrientation = null;
13
+ if (typeof window !== 'undefined') {
14
+ const win = window;
15
+ if ('ondeviceorientationabsolute' in win) {
16
+ win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);
17
+ }
18
+ else if ('ondeviceorientation' in win) {
19
+ win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);
20
+ }
21
+ }
22
+ }
23
+ updateOrientation(event, isAbsolute) {
24
+ let trueHeading = null;
25
+ let magneticHeading = null;
26
+ let headingAccuracy = null;
27
+ if (isAbsolute && event.alpha !== null) {
28
+ trueHeading = (360 - event.alpha) % 360;
29
+ }
30
+ else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {
31
+ magneticHeading = event.webkitCompassHeading;
32
+ headingAccuracy = event.webkitCompassAccuracy;
33
+ }
34
+ else if (event.alpha !== null && event.absolute === true) {
35
+ trueHeading = (360 - event.alpha) % 360;
36
+ }
37
+ else if (event.alpha !== null) {
38
+ magneticHeading = (360 - event.alpha) % 360;
39
+ }
40
+ if (trueHeading !== null || magneticHeading !== null) {
41
+ this.latestOrientation = {
42
+ trueHeading,
43
+ magneticHeading,
44
+ headingAccuracy,
45
+ };
46
+ }
47
+ }
48
+ augmentPosition(pos, isWatch = false) {
49
+ var _a, _b, _c, _d, _e, _f, _g;
50
+ const coords = pos.coords;
51
+ const orientation = isWatch ? this.latestOrientation : null;
52
+ const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;
53
+ return {
54
+ timestamp: pos.timestamp,
55
+ coords: {
56
+ latitude: coords.latitude,
57
+ longitude: coords.longitude,
58
+ accuracy: coords.accuracy,
59
+ altitude: coords.altitude,
60
+ altitudeAccuracy: coords.altitudeAccuracy,
61
+ speed: coords.speed,
62
+ heading: heading,
63
+ magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,
64
+ trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,
65
+ headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,
66
+ course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,
67
+ },
68
+ };
69
+ }
10
70
  async getCurrentPosition(options) {
11
71
  return new Promise((resolve, reject) => {
12
72
  navigator.geolocation.getCurrentPosition((pos) => {
13
- resolve(pos);
73
+ resolve(this.augmentPosition(pos, false));
14
74
  }, (err) => {
15
75
  reject(err);
16
76
  }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));
@@ -18,7 +78,7 @@ var capacitorGeolocationPluginCapacitor = (function (exports, core, synapse) {
18
78
  }
19
79
  async watchPosition(options, callback) {
20
80
  const id = navigator.geolocation.watchPosition((pos) => {
21
- callback(pos);
81
+ callback(this.augmentPosition(pos, true));
22
82
  }, (err) => {
23
83
  callback(null, err);
24
84
  }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(pos);\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(pos);\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nconst Geolocation = new GeolocationWeb();\nexport { Geolocation };\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","exposeSynapse","WebPlugin"],"mappings":";;;AAEK,UAAC,WAAW,GAAGA,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;IAClE,CAAC;AACDC,yBAAa,EAAE;;ICJR,MAAM,cAAc,SAASC,cAAS,CAAC;IAC9C,IAAI,MAAM,kBAAkB,CAAC,OAAO,EAAE;IACtC,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IAChD,YAAY,SAAS,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,GAAG,KAAK;IAC9D,gBAAgB,OAAO,CAAC,GAAG,CAAC;IAC5B,YAAY,CAAC,EAAE,CAAC,GAAG,KAA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AAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE;IAC/E,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;IACoB,IAAI,cAAc;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport { exposeSynapse } from '@capacitor/synapse';\nconst Geolocation = registerPlugin('Geolocation', {\n web: () => import('./web').then((m) => new m.GeolocationWeb()),\n});\nexposeSynapse();\nexport * from './definitions';\nexport { Geolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class GeolocationWeb extends WebPlugin {\n constructor() {\n super();\n this.latestOrientation = null;\n if (typeof window !== 'undefined') {\n const win = window;\n if ('ondeviceorientationabsolute' in win) {\n win.addEventListener('deviceorientationabsolute', (event) => this.updateOrientation(event, true), true);\n }\n else if ('ondeviceorientation' in win) {\n win.addEventListener('deviceorientation', (event) => this.updateOrientation(event, false), true);\n }\n }\n }\n updateOrientation(event, isAbsolute) {\n let trueHeading = null;\n let magneticHeading = null;\n let headingAccuracy = null;\n if (isAbsolute && event.alpha !== null) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.webkitCompassHeading !== undefined && event.webkitCompassHeading !== null) {\n magneticHeading = event.webkitCompassHeading;\n headingAccuracy = event.webkitCompassAccuracy;\n }\n else if (event.alpha !== null && event.absolute === true) {\n trueHeading = (360 - event.alpha) % 360;\n }\n else if (event.alpha !== null) {\n magneticHeading = (360 - event.alpha) % 360;\n }\n if (trueHeading !== null || magneticHeading !== null) {\n this.latestOrientation = {\n trueHeading,\n magneticHeading,\n headingAccuracy,\n };\n }\n }\n augmentPosition(pos, isWatch = false) {\n var _a, _b, _c, _d, _e, _f, _g;\n const coords = pos.coords;\n const orientation = isWatch ? this.latestOrientation : null;\n const heading = (_c = (_b = (_a = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _a !== void 0 ? _a : orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _b !== void 0 ? _b : (isWatch ? coords.heading : null)) !== null && _c !== void 0 ? _c : null;\n return {\n timestamp: pos.timestamp,\n coords: {\n latitude: coords.latitude,\n longitude: coords.longitude,\n accuracy: coords.accuracy,\n altitude: coords.altitude,\n altitudeAccuracy: coords.altitudeAccuracy,\n speed: coords.speed,\n heading: heading,\n magneticHeading: (_d = orientation === null || orientation === void 0 ? void 0 : orientation.magneticHeading) !== null && _d !== void 0 ? _d : null,\n trueHeading: (_e = orientation === null || orientation === void 0 ? void 0 : orientation.trueHeading) !== null && _e !== void 0 ? _e : null,\n headingAccuracy: (_f = orientation === null || orientation === void 0 ? void 0 : orientation.headingAccuracy) !== null && _f !== void 0 ? _f : null,\n course: (_g = (isWatch ? coords.heading : null)) !== null && _g !== void 0 ? _g : null,\n },\n };\n }\n async getCurrentPosition(options) {\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition((pos) => {\n resolve(this.augmentPosition(pos, false));\n }, (err) => {\n reject(err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0 }, options));\n });\n }\n async watchPosition(options, callback) {\n const id = navigator.geolocation.watchPosition((pos) => {\n callback(this.augmentPosition(pos, true));\n }, (err) => {\n callback(null, err);\n }, Object.assign({ enableHighAccuracy: false, timeout: 10000, maximumAge: 0, minimumUpdateInterval: 5000 }, options));\n return `${id}`;\n }\n async clearWatch(options) {\n navigator.geolocation.clearWatch(parseInt(options.id, 10));\n }\n async checkPermissions() {\n if (typeof navigator === 'undefined' || !navigator.permissions) {\n throw this.unavailable('Permissions API not available in this browser');\n }\n const permission = await navigator.permissions.query({\n name: 'geolocation',\n });\n return { location: permission.state, coarseLocation: permission.state };\n }\n async requestPermissions() {\n throw this.unimplemented('Not implemented on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AC,CAAC;IACtB,IAAI;IACJ,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;IAC9B,QAAQ,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAClE,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACxE,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC;IACnF,QAAQ;IACR,QAAQ,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;IAC7D,YAAY,IAAI,EAAE,aAAa;IAC/B,SAAS,CAAC;IACV,QAAQ,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,KAAK,EAAE;IAC/E,IAAI;IACJ,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;IACoB,IAAI,cAAc;;;;;;;;;;;;;;;"}
@@ -33,5 +33,9 @@ enum Constants {
33
33
  static let speed: String = "speed"
34
34
  static let timestamp: String = "timestamp"
35
35
  static let altitudeAccuracy: String = "altitudeAccuracy"
36
+ static let magneticHeading: String = "magneticHeading"
37
+ static let trueHeading: String = "trueHeading"
38
+ static let headingAccuracy: String = "headingAccuracy"
39
+ static let course: String = "course"
36
40
  }
37
41
  }
@@ -10,9 +10,14 @@ extension IONGLOCPositionModel {
10
10
  }
11
11
 
12
12
  private var coordsJSObject: JSObject {
13
- [
13
+ let headingValue = trueHeading ?? magneticHeading ?? (course != -1.0 ? course : nil)
14
+ return [
14
15
  Constants.Position.altitude: altitude,
15
- Constants.Position.heading: course,
16
+ Constants.Position.heading: headingValue ?? NSNull(),
17
+ Constants.Position.magneticHeading: magneticHeading ?? NSNull(),
18
+ Constants.Position.trueHeading: trueHeading ?? NSNull(),
19
+ Constants.Position.headingAccuracy: headingAccuracy ?? NSNull(),
20
+ Constants.Position.course: course != -1.0 ? course : NSNull(),
16
21
  Constants.Position.accuracy: horizontalAccuracy,
17
22
  Constants.Position.latitude: latitude,
18
23
  Constants.Position.longitude: longitude,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/geolocation",
3
- "version": "8.0.0",
3
+ "version": "8.2.0-dev.1",
4
4
  "description": "The Geolocation API provides simple methods for getting and tracking the current position of the device using GPS, along with altitude, heading, and speed information if available.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,11 +39,12 @@
39
39
  "eslint": "eslint . --ext ts",
40
40
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
41
41
  "swiftlint": "node-swiftlint",
42
- "docgen": "docgen --api GeolocationPlugin --output-readme README.md --output-json dist/docs.json && cp README.md ../../README.md",
42
+ "docgen": "docgen --api GeolocationPlugin --output-readme README.md --output-json dist/docs.json",
43
43
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
44
44
  "clean": "rimraf ./dist",
45
45
  "watch": "tsc --watch",
46
- "prepublishOnly": "npm run build"
46
+ "prepublishOnly": "npm run build",
47
+ "publish:cocoapod": "pod trunk push ./CapacitorGeolocation.podspec --allow-warnings"
47
48
  },
48
49
  "dependencies": {
49
50
  "@capacitor/synapse": "^1.0.4"
@@ -87,4 +88,4 @@
87
88
  "src": "android"
88
89
  }
89
90
  }
90
- }
91
+ }