@capacitor/geolocation 1.3.0 → 4.0.0-beta.2

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,60 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.0.0-beta.2](https://github.com/ionic-team/capacitor-plugins/compare/4.0.0-beta.0...4.0.0-beta.2) (2022-07-08)
7
+
8
+ **Note:** Version bump only for package @capacitor/geolocation
9
+
10
+
11
+
12
+
13
+
14
+ # 4.0.0-beta.0 (2022-06-27)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **geolocation:** reject checkPermissions / requestPermissions if location services are disabled ([#1053](https://github.com/ionic-team/capacitor-plugins/issues/1053)) ([774ec6e](https://github.com/ionic-team/capacitor-plugins/commit/774ec6e941193b1b06d07d31e6672340de532385))
20
+ * **geolocation:** stop location requests on pause ([#1018](https://github.com/ionic-team/capacitor-plugins/issues/1018)) ([eb24f25](https://github.com/ionic-team/capacitor-plugins/commit/eb24f2521d05dd25a2087a1de2b3e0644568cda0))
21
+ * add es2017 lib to tsconfig ([#180](https://github.com/ionic-team/capacitor-plugins/issues/180)) ([2c3776c](https://github.com/ionic-team/capacitor-plugins/commit/2c3776c38ca025c5ee965dec10ccf1cdb6c02e2f))
22
+ * correct addListeners links ([#655](https://github.com/ionic-team/capacitor-plugins/issues/655)) ([f9871e7](https://github.com/ionic-team/capacitor-plugins/commit/f9871e7bd53478addb21155e148829f550c0e457))
23
+ * inline source code in esm map files ([#760](https://github.com/ionic-team/capacitor-plugins/issues/760)) ([a960489](https://github.com/ionic-team/capacitor-plugins/commit/a960489a19db0182b90d187a50deff9dfbe51038))
24
+ * remove postpublish scripts ([#656](https://github.com/ionic-team/capacitor-plugins/issues/656)) ([ed6ac49](https://github.com/ionic-team/capacitor-plugins/commit/ed6ac499ebf4a47525071ccbfc36c27503e11f60))
25
+ * **geolocation:** Make getCurrentPosition return only once ([#470](https://github.com/ionic-team/capacitor-plugins/issues/470)) ([c5f1ceb](https://github.com/ionic-team/capacitor-plugins/commit/c5f1ceb790910b92e3f64d0b7fa8c85d48ea9841))
26
+ * **geolocation:** Replace deprecated call.save with new keepAlive API ([#375](https://github.com/ionic-team/capacitor-plugins/issues/375)) ([e4e7cf4](https://github.com/ionic-team/capacitor-plugins/commit/e4e7cf4afd4a70bf48359c625fa7a548211876d5))
27
+ * **geolocation:** return cached location if newer than maximumAge ([#639](https://github.com/ionic-team/capacitor-plugins/issues/639)) ([7b08eea](https://github.com/ionic-team/capacitor-plugins/commit/7b08eea9729bbf2b2b6b881cc81389cf108b3a2c))
28
+ * **geolocation:** Use the new APIs for handling/saving calls ([#374](https://github.com/ionic-team/capacitor-plugins/issues/374)) ([ebd5b52](https://github.com/ionic-team/capacitor-plugins/commit/ebd5b527cb7f8b6c0016e82d03a0e84287913d3e))
29
+ * support deprecated types from Capacitor 2 ([#139](https://github.com/ionic-team/capacitor-plugins/issues/139)) ([2d7127a](https://github.com/ionic-team/capacitor-plugins/commit/2d7127a488e26f0287951921a6db47c49d817336))
30
+
31
+
32
+ ### Features
33
+
34
+ * set targetSDK default value to 31 ([#824](https://github.com/ionic-team/capacitor-plugins/issues/824)) ([3ee10de](https://github.com/ionic-team/capacitor-plugins/commit/3ee10de98067984c1a4e75295d001c5a895c47f4))
35
+ * set targetSDK default value to 32 ([#970](https://github.com/ionic-team/capacitor-plugins/issues/970)) ([fa70d96](https://github.com/ionic-team/capacitor-plugins/commit/fa70d96f141af751aae53ceb5642c46b204f5958))
36
+ * Upgrade gradle to 7.4 ([#826](https://github.com/ionic-team/capacitor-plugins/issues/826)) ([5db0906](https://github.com/ionic-team/capacitor-plugins/commit/5db0906f6264287c4f8e69dbaecf19d4d387824b))
37
+ * Use java 11 ([#910](https://github.com/ionic-team/capacitor-plugins/issues/910)) ([5acb2a2](https://github.com/ionic-team/capacitor-plugins/commit/5acb2a288a413492b163e4e97da46a085d9e4be0))
38
+ * **android:** implements Activity Result API changes for permissions and activity results ([#222](https://github.com/ionic-team/capacitor-plugins/issues/222)) ([f671b9f](https://github.com/ionic-team/capacitor-plugins/commit/f671b9f4b472806ef43db6dcf302d4503cf1828c))
39
+ * **geolocation:** Add new alias for coarse location ([#684](https://github.com/ionic-team/capacitor-plugins/issues/684)) ([7563040](https://github.com/ionic-team/capacitor-plugins/commit/7563040983ad397e28616246e7ed5ffce69727c2))
40
+ * **geolocation:** Error if Google Play Services are not available ([#709](https://github.com/ionic-team/capacitor-plugins/issues/709)) ([fc79c43](https://github.com/ionic-team/capacitor-plugins/commit/fc79c4319c54cbcd5dbbb7221dfdd03d0515805b))
41
+ * **geolocation:** Throw error if location is disabled ([#589](https://github.com/ionic-team/capacitor-plugins/issues/589)) ([14724c5](https://github.com/ionic-team/capacitor-plugins/commit/14724c5ec5b23bf94f6f3511bbe204482768d10f))
42
+ * add commonjs output format ([#179](https://github.com/ionic-team/capacitor-plugins/issues/179)) ([8e9e098](https://github.com/ionic-team/capacitor-plugins/commit/8e9e09862064b3f6771d7facbc4008e995d9b463))
43
+ * Geolocation plugin ([#13](https://github.com/ionic-team/capacitor-plugins/issues/13)) ([911ae71](https://github.com/ionic-team/capacitor-plugins/commit/911ae71e6aef4cfa9fb3ab5b0c13f3c06ef6b15c))
44
+
45
+
46
+
47
+
48
+
49
+ ## [1.3.1](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/geolocation@1.3.0...@capacitor/geolocation@1.3.1) (2022-01-19)
50
+
51
+
52
+ ### Bug Fixes
53
+
54
+ * inline source code in esm map files ([#760](https://github.com/ionic-team/capacitor-plugins/issues/760)) ([a960489](https://github.com/ionic-team/capacitor-plugins/commit/a960489a19db0182b90d187a50deff9dfbe51038))
55
+
56
+
57
+
58
+
59
+
6
60
  # [1.3.0](https://github.com/ionic-team/capacitor-plugins/compare/@capacitor/geolocation@1.2.0...@capacitor/geolocation@1.3.0) (2021-12-08)
7
61
 
8
62
 
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => 'https://github.com/ionic-team/capacitor-plugins.git', :tag => package['name'] + '@' + package['version'] }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}', 'geolocation/ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '12.0'
14
+ s.ios.deployment_target = '13.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/README.md CHANGED
@@ -37,7 +37,7 @@ Read about [Setting Permissions](https://capacitorjs.com/docs/android/configurat
37
37
 
38
38
  This plugin will use the following project variables (defined in your app's `variables.gradle` file):
39
39
 
40
- - `$playServicesLocationVersion` version of `com.google.android.gms:play-services-location` (default: `17.1.0`)
40
+ - `$playServicesLocationVersion` version of `com.google.android.gms:play-services-location` (default: `20.0.0`)
41
41
 
42
42
  ## Example
43
43
 
@@ -131,7 +131,7 @@ Clear a given watch
131
131
  checkPermissions() => Promise<PermissionStatus>
132
132
  ```
133
133
 
134
- Check location permissions
134
+ Check location permissions. Will throw if system location services are disabled.
135
135
 
136
136
  **Returns:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>
137
137
 
@@ -146,7 +146,7 @@ Check location permissions
146
146
  requestPermissions(permissions?: GeolocationPluginPermissions | undefined) => Promise<PermissionStatus>
147
147
  ```
148
148
 
149
- Request location permissions
149
+ Request location permissions. Will throw if system location services are disabled.
150
150
 
151
151
  | Param | Type |
152
152
  | ----------------- | ------------------------------------------------------------------------------------- |
@@ -175,7 +175,7 @@ Request location permissions
175
175
  | Prop | Type | Description | Default | Since |
176
176
  | ------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
177
177
  | **`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 |
178
- | **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates | <code>10000</code> | 1.0.0 |
178
+ | **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | <code>10000</code> | 1.0.0 |
179
179
  | **`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 |
180
180
 
181
181
 
@@ -1,8 +1,8 @@
1
1
  ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
4
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
5
- playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '17.1.0'
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
4
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
5
+ playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '20.0.0'
6
6
  }
7
7
 
8
8
  buildscript {
@@ -11,17 +11,17 @@ buildscript {
11
11
  mavenCentral()
12
12
  }
13
13
  dependencies {
14
- classpath 'com.android.tools.build:gradle:4.2.1'
14
+ classpath 'com.android.tools.build:gradle:7.2.1'
15
15
  }
16
16
  }
17
17
 
18
18
  apply plugin: 'com.android.library'
19
19
 
20
20
  android {
21
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
22
22
  defaultConfig {
23
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
25
25
  versionCode 1
26
26
  versionName "1.0"
27
27
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -36,14 +36,13 @@ android {
36
36
  abortOnError false
37
37
  }
38
38
  compileOptions {
39
- sourceCompatibility JavaVersion.VERSION_1_8
40
- targetCompatibility JavaVersion.VERSION_1_8
39
+ sourceCompatibility JavaVersion.VERSION_11
40
+ targetCompatibility JavaVersion.VERSION_11
41
41
  }
42
42
  }
43
43
 
44
44
  repositories {
45
45
  google()
46
- jcenter()
47
46
  mavenCentral()
48
47
  }
49
48
 
@@ -12,6 +12,7 @@ import com.google.android.gms.location.LocationCallback;
12
12
  import com.google.android.gms.location.LocationRequest;
13
13
  import com.google.android.gms.location.LocationResult;
14
14
  import com.google.android.gms.location.LocationServices;
15
+ import com.google.android.gms.location.Priority;
15
16
 
16
17
  public class Geolocation {
17
18
 
@@ -24,50 +25,77 @@ public class Geolocation {
24
25
  this.context = context;
25
26
  }
26
27
 
27
- public void sendLocation(
28
- boolean enableHighAccuracy,
29
- int timeout,
30
- final boolean getCurrentPosition,
31
- final LocationResultCallback resultCallback
32
- ) {
33
- requestLocationUpdates(enableHighAccuracy, timeout, getCurrentPosition, resultCallback);
28
+ public Boolean isLocationServicesEnabled() {
29
+ LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
30
+ return LocationManagerCompat.isLocationEnabled(lm);
34
31
  }
35
32
 
36
33
  @SuppressWarnings("MissingPermission")
37
- public void requestLocationUpdates(
38
- boolean enableHighAccuracy,
39
- int timeout,
40
- final boolean getCurrentPosition,
41
- final LocationResultCallback resultCallback
42
- ) {
34
+ public void sendLocation(boolean enableHighAccuracy, final LocationResultCallback resultCallback) {
35
+ int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
36
+ if (resultCode == ConnectionResult.SUCCESS) {
37
+ LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
38
+
39
+ if (this.isLocationServicesEnabled()) {
40
+ boolean networkEnabled = false;
41
+
42
+ try {
43
+ networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
44
+ } catch (Exception ex) {}
45
+
46
+ int lowPriority = networkEnabled ? Priority.PRIORITY_BALANCED_POWER_ACCURACY : Priority.PRIORITY_LOW_POWER;
47
+ int priority = enableHighAccuracy ? Priority.PRIORITY_HIGH_ACCURACY : lowPriority;
48
+
49
+ LocationServices
50
+ .getFusedLocationProviderClient(context)
51
+ .getCurrentLocation(priority, null)
52
+ .addOnFailureListener(e -> resultCallback.error(e.getMessage()))
53
+ .addOnSuccessListener(
54
+ location -> {
55
+ if (location == null) {
56
+ resultCallback.error("location unavailable");
57
+ } else {
58
+ resultCallback.success(location);
59
+ }
60
+ }
61
+ );
62
+ } else {
63
+ resultCallback.error("location disabled");
64
+ }
65
+ } else {
66
+ resultCallback.error("Google Play Services not available");
67
+ }
68
+ }
69
+
70
+ @SuppressWarnings("MissingPermission")
71
+ public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, final LocationResultCallback resultCallback) {
43
72
  int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
44
73
  if (resultCode == ConnectionResult.SUCCESS) {
45
74
  clearLocationUpdates();
46
75
  fusedLocationClient = LocationServices.getFusedLocationProviderClient(context);
47
76
 
48
77
  LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
49
- if (LocationManagerCompat.isLocationEnabled(lm)) {
78
+ if (this.isLocationServicesEnabled()) {
50
79
  boolean networkEnabled = false;
51
80
 
52
81
  try {
53
82
  networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
54
83
  } catch (Exception ex) {}
55
84
 
56
- LocationRequest locationRequest = new LocationRequest();
57
- locationRequest.setMaxWaitTime(timeout);
58
- locationRequest.setInterval(10000);
59
- locationRequest.setFastestInterval(5000);
60
- int lowPriority = networkEnabled ? LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY : LocationRequest.PRIORITY_LOW_POWER;
61
- int priority = enableHighAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : lowPriority;
62
- locationRequest.setPriority(priority);
85
+ int lowPriority = networkEnabled ? Priority.PRIORITY_BALANCED_POWER_ACCURACY : Priority.PRIORITY_LOW_POWER;
86
+ int priority = enableHighAccuracy ? Priority.PRIORITY_HIGH_ACCURACY : lowPriority;
87
+
88
+ LocationRequest locationRequest = LocationRequest
89
+ .create()
90
+ .setMaxWaitTime(timeout)
91
+ .setInterval(10000)
92
+ .setFastestInterval(5000)
93
+ .setPriority(priority);
63
94
 
64
95
  locationCallback =
65
96
  new LocationCallback() {
66
97
  @Override
67
98
  public void onLocationResult(LocationResult locationResult) {
68
- if (getCurrentPosition) {
69
- clearLocationUpdates();
70
- }
71
99
  Location lastLocation = locationResult.getLastLocation();
72
100
  if (lastLocation == null) {
73
101
  resultCallback.error("location unavailable");
@@ -36,6 +36,41 @@ public class GeolocationPlugin extends Plugin {
36
36
  implementation = new Geolocation(getContext());
37
37
  }
38
38
 
39
+ @Override
40
+ protected void handleOnPause() {
41
+ super.handleOnPause();
42
+ // Clear all location updates on pause to avoid possible background location calls
43
+ implementation.clearLocationUpdates();
44
+ }
45
+
46
+ @Override
47
+ protected void handleOnResume() {
48
+ super.handleOnResume();
49
+ for (PluginCall call : watchingCalls.values()) {
50
+ startWatch(call);
51
+ }
52
+ }
53
+
54
+ @Override
55
+ @PluginMethod
56
+ public void checkPermissions(PluginCall call) {
57
+ if (implementation.isLocationServicesEnabled()) {
58
+ super.checkPermissions(call);
59
+ } else {
60
+ call.reject("Location services are not enabled");
61
+ }
62
+ }
63
+
64
+ @Override
65
+ @PluginMethod
66
+ public void requestPermissions(PluginCall call) {
67
+ if (implementation.isLocationServicesEnabled()) {
68
+ super.requestPermissions(call);
69
+ } else {
70
+ call.reject("Location services are not enabled");
71
+ }
72
+ }
73
+
39
74
  /**
40
75
  * Gets a snapshot of the current device position if permission is granted. The call continues
41
76
  * in the {@link #completeCurrentPosition(PluginCall)} method if a permission request is required.
@@ -60,12 +95,8 @@ public class GeolocationPlugin extends Plugin {
60
95
  @PermissionCallback
61
96
  private void completeCurrentPosition(PluginCall call) {
62
97
  if (getPermissionState(GeolocationPlugin.COARSE_LOCATION) == PermissionState.GRANTED) {
63
- int timeout = call.getInt("timeout", 10000);
64
-
65
98
  implementation.sendLocation(
66
99
  isHighAccuracy(call),
67
- timeout,
68
- true,
69
100
  new LocationResultCallback() {
70
101
  @Override
71
102
  public void success(Location location) {
@@ -116,7 +147,6 @@ public class GeolocationPlugin extends Plugin {
116
147
 
117
148
  @SuppressWarnings("MissingPermission")
118
149
  private void getPosition(PluginCall call) {
119
- int timeout = call.getInt("timeout", 10000);
120
150
  int maximumAge = call.getInt("maximumAge", 0);
121
151
  Location location = implementation.getLastLocation(maximumAge);
122
152
  if (location != null) {
@@ -124,8 +154,6 @@ public class GeolocationPlugin extends Plugin {
124
154
  } else {
125
155
  implementation.sendLocation(
126
156
  isHighAccuracy(call),
127
- timeout,
128
- true,
129
157
  new LocationResultCallback() {
130
158
  @Override
131
159
  public void success(Location location) {
@@ -148,7 +176,6 @@ public class GeolocationPlugin extends Plugin {
148
176
  implementation.requestLocationUpdates(
149
177
  isHighAccuracy(call),
150
178
  timeout,
151
- false,
152
179
  new LocationResultCallback() {
153
180
  @Override
154
181
  public void success(Location location) {
@@ -200,7 +227,7 @@ public class GeolocationPlugin extends Plugin {
200
227
  coords.put("longitude", location.getLongitude());
201
228
  coords.put("accuracy", location.getAccuracy());
202
229
  coords.put("altitude", location.getAltitude());
203
- if (Build.VERSION.SDK_INT >= 26) {
230
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
204
231
  coords.put("altitudeAccuracy", location.getVerticalAccuracyMeters());
205
232
  }
206
233
  coords.put("speed", location.getSpeed());
@@ -210,8 +237,7 @@ public class GeolocationPlugin extends Plugin {
210
237
 
211
238
  private String getAlias(PluginCall call) {
212
239
  String alias = GeolocationPlugin.LOCATION;
213
- // TODO replace with Build.VERSION_CODES.S once we target SDK 31
214
- if (Build.VERSION.SDK_INT >= 31) {
240
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
215
241
  boolean enableHighAccuracy = call.getBoolean("enableHighAccuracy", false);
216
242
  if (!enableHighAccuracy) {
217
243
  alias = GeolocationPlugin.COARSE_LOCATION;
package/dist/docs.json CHANGED
@@ -93,7 +93,7 @@
93
93
  "text": "1.0.0"
94
94
  }
95
95
  ],
96
- "docs": "Check location permissions",
96
+ "docs": "Check location permissions. Will throw if system location services are disabled.",
97
97
  "complexTypes": [
98
98
  "PermissionStatus"
99
99
  ],
@@ -116,7 +116,7 @@
116
116
  "text": "1.0.0"
117
117
  }
118
118
  ],
119
- "docs": "Request location permissions",
119
+ "docs": "Request location permissions. Will throw if system location services are disabled.",
120
120
  "complexTypes": [
121
121
  "PermissionStatus",
122
122
  "GeolocationPluginPermissions"
@@ -195,7 +195,7 @@
195
195
  "name": "since"
196
196
  }
197
197
  ],
198
- "docs": "The maximum wait time in milliseconds for location updates",
198
+ "docs": "The maximum wait time in milliseconds for location updates.\n\nIn Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition.",
199
199
  "complexTypes": [],
200
200
  "type": "number | undefined"
201
201
  },
@@ -52,13 +52,13 @@ export interface GeolocationPlugin {
52
52
  */
53
53
  clearWatch(options: ClearWatchOptions): Promise<void>;
54
54
  /**
55
- * Check location permissions
55
+ * Check location permissions. Will throw if system location services are disabled.
56
56
  *
57
57
  * @since 1.0.0
58
58
  */
59
59
  checkPermissions(): Promise<PermissionStatus>;
60
60
  /**
61
- * Request location permissions
61
+ * Request location permissions. Will throw if system location services are disabled.
62
62
  *
63
63
  * @since 1.0.0
64
64
  */
@@ -138,7 +138,9 @@ export interface PositionOptions {
138
138
  */
139
139
  enableHighAccuracy?: boolean;
140
140
  /**
141
- * The maximum wait time in milliseconds for location updates
141
+ * The maximum wait time in milliseconds for location updates.
142
+ *
143
+ * In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition.
142
144
  *
143
145
  * @default 10000
144
146
  * @since 1.0.0
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
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(\n options: PositionOptions,\n callback: WatchPositionCallback,\n ): 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 * @since 1.0.0\n */\n requestPermissions(\n permissions?: GeolocationPluginPermissions,\n ): 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 * In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition.\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\nexport type WatchPositionCallback = (\n position: Position | null,\n err?: any,\n) => 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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,WAAW,GAAG,cAAc,CAAoB,aAAa,EAAE;IACnE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC7D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,WAAW,GAAG,cAAc,CAAoB,aAAa,EAAE;IACnE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC7D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { GeolocationPlugin } from './definitions';\n\nconst Geolocation = registerPlugin<GeolocationPlugin>('Geolocation', {\n web: () => import('./web').then(m => new m.GeolocationWeb()),\n});\n\nexport * from './definitions';\nexport { Geolocation };\n"]}
@@ -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,SAAS;IAC3C,KAAK,CAAC,kBAAkB,CAAC,OAAyB;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,SAAS,CAAC,WAAW,CAAC,kBAAkB,CACtC,GAAG,CAAC,EAAE;gBACJ,OAAO,CAAC,GAAG,CAAC,CAAC;YACf,CAAC,EACD,GAAG,CAAC,EAAE;gBACJ,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC,kBAEC,kBAAkB,EAAE,KAAK,EACzB,OAAO,EAAE,KAAK,EACd,UAAU,EAAE,CAAC,IACV,OAAO,EAEb,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,OAAwB,EACxB,QAA+B;QAE/B,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAC5C,GAAG,CAAC,EAAE;YACJ,QAAQ,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC,EACD,GAAG,CAAC,EAAE;YACJ,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC,kBAEC,kBAAkB,EAAE,KAAK,EACzB,OAAO,EAAE,KAAK,EACd,UAAU,EAAE,CAAC,IACV,OAAO,EAEb,CAAC;QAEF,OAAO,GAAG,EAAE,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAuB;QACtC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YAC9D,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC;SACzE;QAED,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YAC1D,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"}
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;IAC3C,KAAK,CAAC,kBAAkB,CAAC,OAAyB;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,SAAS,CAAC,WAAW,CAAC,kBAAkB,CACtC,GAAG,CAAC,EAAE;gBACJ,OAAO,CAAC,GAAG,CAAC,CAAC;YACf,CAAC,EACD,GAAG,CAAC,EAAE;gBACJ,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC,kBAEC,kBAAkB,EAAE,KAAK,EACzB,OAAO,EAAE,KAAK,EACd,UAAU,EAAE,CAAC,IACV,OAAO,EAEb,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,OAAwB,EACxB,QAA+B;QAE/B,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAC5C,GAAG,CAAC,EAAE;YACJ,QAAQ,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC,EACD,GAAG,CAAC,EAAE;YACJ,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtB,CAAC,kBAEC,kBAAkB,EAAE,KAAK,EACzB,OAAO,EAAE,KAAK,EACd,UAAU,EAAE,CAAC,IACV,OAAO,EAEb,CAAC;QAEF,OAAO,GAAG,EAAE,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAuB;QACtC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YAC9D,MAAM,IAAI,CAAC,WAAW,CAAC,+CAA+C,CAAC,CAAC;SACzE;QAED,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;YAC1D,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(\n options: PositionOptions,\n callback: WatchPositionCallback,\n ): 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 ...options,\n },\n );\n\n return `${id}`;\n }\n\n async clearWatch(options: { id: string }): Promise<void> {\n window.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 window.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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/geolocation",
3
- "version": "1.3.0",
3
+ "version": "4.0.0-beta.2",
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",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32
- "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
32
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
33
33
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
34
  "verify:web": "npm run build",
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
@@ -45,10 +45,10 @@
45
45
  "publish:cocoapod": "pod trunk push ./CapacitorGeolocation.podspec --allow-warnings"
46
46
  },
47
47
  "devDependencies": {
48
- "@capacitor/android": "^3.0.0",
49
- "@capacitor/core": "^3.0.0",
48
+ "@capacitor/android": "next",
49
+ "@capacitor/core": "next",
50
50
  "@capacitor/docgen": "0.0.18",
51
- "@capacitor/ios": "^3.0.0",
51
+ "@capacitor/ios": "next",
52
52
  "@ionic/eslint-config": "^0.3.0",
53
53
  "@ionic/prettier-config": "~1.0.1",
54
54
  "@ionic/swiftlint-config": "^1.1.2",
@@ -61,7 +61,7 @@
61
61
  "typescript": "~4.1.5"
62
62
  },
63
63
  "peerDependencies": {
64
- "@capacitor/core": "^3.0.0"
64
+ "@capacitor/core": "next"
65
65
  },
66
66
  "prettier": "@ionic/prettier-config",
67
67
  "swiftlint": "@ionic/swiftlint-config",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "d378c00d51b1c9fb978772906448fa0ec9cb81d0"
82
+ "gitHead": "32240b675c12a774920c07a86b4483ecec7a9c8d"
83
83
  }