@capgo/background-geolocation 7.0.20 → 7.1.0

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/README.md CHANGED
@@ -197,6 +197,7 @@ Configration specific to Android can be made in `strings.xml`:
197
197
  * [`stop()`](#stop)
198
198
  * [`openSettings()`](#opensettings)
199
199
  * [`setPlannedRoute(...)`](#setplannedroute)
200
+ * [`getPluginVersion()`](#getpluginversion)
200
201
  * [Interfaces](#interfaces)
201
202
 
202
203
  </docgen-index>
@@ -272,6 +273,19 @@ This should be used to play a sound (in the background too, only for native).
272
273
  --------------------
273
274
 
274
275
 
276
+ ### getPluginVersion()
277
+
278
+ ```typescript
279
+ getPluginVersion() => Promise<{ version: string; }>
280
+ ```
281
+
282
+ Get the native Capacitor plugin version
283
+
284
+ **Returns:** <code>Promise&lt;{ version: string; }&gt;</code>
285
+
286
+ --------------------
287
+
288
+
275
289
  ### Interfaces
276
290
 
277
291
 
@@ -42,6 +42,8 @@ import org.json.JSONObject;
42
42
  )
43
43
  public class BackgroundGeolocation extends Plugin {
44
44
 
45
+ private final String PLUGIN_VERSION = "";
46
+
45
47
  private CompletableFuture<BackgroundGeolocationService.LocalBinder> serviceConnectionFuture;
46
48
  private CompletableFuture<Void> locationPermissionFuture;
47
49
 
@@ -346,4 +348,15 @@ public class BackgroundGeolocation extends Plugin {
346
348
  }
347
349
  super.handleOnDestroy();
348
350
  }
351
+
352
+ @PluginMethod
353
+ public void getPluginVersion(final PluginCall call) {
354
+ try {
355
+ final JSObject ret = new JSObject();
356
+ ret.put("version", this.PLUGIN_VERSION);
357
+ call.resolve(ret);
358
+ } catch (final Exception e) {
359
+ call.reject("Could not get plugin version", e);
360
+ }
361
+ }
349
362
  }
package/dist/docs.json CHANGED
@@ -136,6 +136,25 @@
136
136
  "SetPlannedRouteOptions"
137
137
  ],
138
138
  "slug": "setplannedroute"
139
+ },
140
+ {
141
+ "name": "getPluginVersion",
142
+ "signature": "() => Promise<{ version: string; }>",
143
+ "parameters": [],
144
+ "returns": "Promise<{ version: string; }>",
145
+ "tags": [
146
+ {
147
+ "name": "returns",
148
+ "text": "an Promise with version for this device"
149
+ },
150
+ {
151
+ "name": "throws",
152
+ "text": "An error if the something went wrong"
153
+ }
154
+ ],
155
+ "docs": "Get the native Capacitor plugin version",
156
+ "complexTypes": [],
157
+ "slug": "getpluginversion"
139
158
  }
140
159
  ],
141
160
  "properties": []
@@ -265,4 +265,13 @@ export interface BackgroundGeolocationPlugin {
265
265
  * });
266
266
  */
267
267
  setPlannedRoute(options: SetPlannedRouteOptions): Promise<void>;
268
+ /**
269
+ * Get the native Capacitor plugin version
270
+ *
271
+ * @returns {Promise<{ id: string }>} an Promise with version for this device
272
+ * @throws An error if the something went wrong
273
+ */
274
+ getPluginVersion(): Promise<{
275
+ version: string;
276
+ }>;
268
277
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The options for configuring for location updates.\n *\n * @since 7.0.9\n */\nexport interface StartOptions {\n /**\n * If the \"backgroundMessage\" option is defined, the plugin will\n * provide location updates whether the app is in the background or the\n * foreground. If it is not defined, location updates are only\n * guaranteed in the foreground. This is true on both platforms.\n *\n * On Android, a notification must be shown to continue receiving\n * location updates in the background. This option specifies the text of\n * that notification.\n *\n * @since 7.0.9\n * @example \"Getting your location to provide better service\"\n */\n backgroundMessage?: string;\n /**\n * The title of the notification mentioned above.\n *\n * @since 7.0.9\n * @default \"Using your location\"\n * @example \"Location Service\"\n */\n backgroundTitle?: string;\n /**\n * Whether permissions should be requested from the user automatically,\n * if they are not already granted.\n *\n * @since 7.0.9\n * @default true\n * @example\n * // Auto-request permissions\n * requestPermissions: true\n *\n * // Don't auto-request, handle manually\n * requestPermissions: false\n */\n requestPermissions?: boolean;\n /**\n * If \"true\", stale locations may be delivered while the device\n * obtains a GPS fix. You are responsible for checking the \"time\"\n * property. If \"false\", locations are guaranteed to be up to date.\n *\n * @since 7.0.9\n * @default false\n * @example\n * // Allow stale locations for faster initial response\n * stale: true\n *\n * // Only fresh locations\n * stale: false\n */\n stale?: boolean;\n /**\n * The distance in meters that the device must move before a new location update is triggered.\n * This is used to filter out small movements and reduce the number of updates.\n *\n * @since 7.0.9\n * @default 0\n * @example\n * // Update every 10 meters\n * distanceFilter: 10\n *\n * // Update on any movement\n * distanceFilter: 0\n */\n distanceFilter?: number;\n}\n\n/**\n * Represents a geographical location with various attributes.\n * Contains all the standard location properties returned by GPS/network providers.\n *\n * @since 7.0.0\n */\nexport interface Location {\n /**\n * Latitude in degrees.\n * Range: -90.0 to +90.0\n *\n * @since 7.0.0\n * @example 40.7128\n */\n latitude: number;\n /**\n * Longitude in degrees.\n * Range: -180.0 to +180.0\n *\n * @since 7.0.0\n * @example -74.0060\n */\n longitude: number;\n /**\n * Radius of horizontal uncertainty in metres, with 68% confidence.\n * Lower values indicate more accurate location.\n *\n * @since 7.0.0\n * @example 5.0\n */\n accuracy: number;\n /**\n * Metres above sea level (or null if not available).\n *\n * @since 7.0.0\n * @example 10.5\n */\n altitude: number | null;\n /**\n * Vertical uncertainty in metres, with 68% confidence (or null if not available).\n *\n * @since 7.0.0\n * @example 3.0\n */\n altitudeAccuracy: number | null;\n /**\n * `true` if the location was simulated by software, rather than GPS.\n * Useful for detecting mock locations in development or testing.\n *\n * @since 7.0.0\n * @example false\n */\n simulated: boolean;\n /**\n * Deviation from true north in degrees (or null if not available).\n * Range: 0.0 to 360.0\n *\n * @since 7.0.0\n * @example 45.5\n */\n bearing: number | null;\n /**\n * Speed in metres per second (or null if not available).\n *\n * @since 7.0.0\n * @example 2.5\n */\n speed: number | null;\n /**\n * Time the location was produced, in milliseconds since the unix epoch.\n * Use this to check if a location is stale when using stale: true.\n *\n * @since 7.0.0\n * @example 1640995200000\n */\n time: number | null;\n}\n\n/**\n * Error object that may be passed to the location start callback.\n * Extends the standard Error with optional error codes.\n *\n * @since 7.0.0\n */\nexport interface CallbackError extends Error {\n /**\n * Optional error code for more specific error handling.\n *\n * @since 7.0.0\n * @example \"PERMISSION_DENIED\"\n */\n code?: string;\n}\n\nexport interface SetPlannedRouteOptions {\n /**\n * The name of the sound file to play.\n * Must be a valid sound relative path in the app's public folder to work for both web and native platforms.\n * There's no need to include the public folder in the path.\n * @since 7.0.10\n * @example \"notification.mp3\"\n * */\n soundFile: string;\n /**\n * The planned route as an array of longitude and latitude pairs.\n * Each pair represents a point on the route.\n * This is used to define a route that the user can follow.\n * The route is used to play a sound when the user deviates from it.\n * @since 7.0.11\n * @example [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n */\n route: [number, number][];\n\n /**\n * The distance in meters that the user must deviate from the planned route to trigger the sound.\n * This is used to determine how far off the route the user can be before the sound is played.\n * If not specified, a default value of 50 meters is used.\n * @since 7.0.11\n * @default 50\n * @example 50\n */\n distance: number;\n}\n\n/**\n * Main plugin interface for background geolocation functionality.\n * Provides methods to manage location updates and access device settings.\n *\n * @since 7.0.0\n */\nexport interface BackgroundGeolocationPlugin {\n /**\n * To start listening for changes in the device's location, call this method.\n * A Promise is returned to indicate that it finished the call. The callback will be called every time a new location\n * is available, or if there was an error when calling this method. Don't rely on promise rejection for this.\n *\n * @param options The configuration options\n * @param callback The callback function invoked when a new location is available or an error occurs\n * @returns A promise that resolves when the method is successfully called\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.start(\n * {\n * backgroundMessage: \"App is using your location in the background\",\n * backgroundTitle: \"Location Service\",\n * requestPermissions: true,\n * stale: false,\n * distanceFilter: 10\n * },\n * (location, error) => {\n * if (error) {\n * console.error('Location error:', error);\n * return;\n * }\n * if (location) {\n * console.log('New location:', location.latitude, location.longitude);\n * }\n * }\n * );\n */\n start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void>;\n\n /**\n * Stops location updates.\n *\n * @returns A promise that resolves when the plugin stops successfully removed\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.stop();\n */\n stop(): Promise<void>;\n\n /**\n * Opens the device's location settings page.\n * Useful for directing users to enable location services or adjust permissions.\n *\n * @returns A promise that resolves when the settings page is opened\n *\n * @since 7.0.0\n * @example\n * // Direct user to location settings\n * await BackgroundGeolocation.openSettings();\n */\n openSettings(): Promise<void>;\n\n /**\n * Plays a sound file when the user deviates from the planned route.\n * This should be used to play a sound (in the background too, only for native).\n *\n * @param options The options for setting the planned route and sound file\n * @returns A promise that resolves when the route is set successfully\n *\n * @since 7.0.11\n * @example\n * await BackgroundGeolocation.setPlannedRoute({\n * soundFile: \"notification.mp3\",\n * route: [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n * });\n */\n setPlannedRoute(options: SetPlannedRouteOptions): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The options for configuring for location updates.\n *\n * @since 7.0.9\n */\nexport interface StartOptions {\n /**\n * If the \"backgroundMessage\" option is defined, the plugin will\n * provide location updates whether the app is in the background or the\n * foreground. If it is not defined, location updates are only\n * guaranteed in the foreground. This is true on both platforms.\n *\n * On Android, a notification must be shown to continue receiving\n * location updates in the background. This option specifies the text of\n * that notification.\n *\n * @since 7.0.9\n * @example \"Getting your location to provide better service\"\n */\n backgroundMessage?: string;\n /**\n * The title of the notification mentioned above.\n *\n * @since 7.0.9\n * @default \"Using your location\"\n * @example \"Location Service\"\n */\n backgroundTitle?: string;\n /**\n * Whether permissions should be requested from the user automatically,\n * if they are not already granted.\n *\n * @since 7.0.9\n * @default true\n * @example\n * // Auto-request permissions\n * requestPermissions: true\n *\n * // Don't auto-request, handle manually\n * requestPermissions: false\n */\n requestPermissions?: boolean;\n /**\n * If \"true\", stale locations may be delivered while the device\n * obtains a GPS fix. You are responsible for checking the \"time\"\n * property. If \"false\", locations are guaranteed to be up to date.\n *\n * @since 7.0.9\n * @default false\n * @example\n * // Allow stale locations for faster initial response\n * stale: true\n *\n * // Only fresh locations\n * stale: false\n */\n stale?: boolean;\n /**\n * The distance in meters that the device must move before a new location update is triggered.\n * This is used to filter out small movements and reduce the number of updates.\n *\n * @since 7.0.9\n * @default 0\n * @example\n * // Update every 10 meters\n * distanceFilter: 10\n *\n * // Update on any movement\n * distanceFilter: 0\n */\n distanceFilter?: number;\n}\n\n/**\n * Represents a geographical location with various attributes.\n * Contains all the standard location properties returned by GPS/network providers.\n *\n * @since 7.0.0\n */\nexport interface Location {\n /**\n * Latitude in degrees.\n * Range: -90.0 to +90.0\n *\n * @since 7.0.0\n * @example 40.7128\n */\n latitude: number;\n /**\n * Longitude in degrees.\n * Range: -180.0 to +180.0\n *\n * @since 7.0.0\n * @example -74.0060\n */\n longitude: number;\n /**\n * Radius of horizontal uncertainty in metres, with 68% confidence.\n * Lower values indicate more accurate location.\n *\n * @since 7.0.0\n * @example 5.0\n */\n accuracy: number;\n /**\n * Metres above sea level (or null if not available).\n *\n * @since 7.0.0\n * @example 10.5\n */\n altitude: number | null;\n /**\n * Vertical uncertainty in metres, with 68% confidence (or null if not available).\n *\n * @since 7.0.0\n * @example 3.0\n */\n altitudeAccuracy: number | null;\n /**\n * `true` if the location was simulated by software, rather than GPS.\n * Useful for detecting mock locations in development or testing.\n *\n * @since 7.0.0\n * @example false\n */\n simulated: boolean;\n /**\n * Deviation from true north in degrees (or null if not available).\n * Range: 0.0 to 360.0\n *\n * @since 7.0.0\n * @example 45.5\n */\n bearing: number | null;\n /**\n * Speed in metres per second (or null if not available).\n *\n * @since 7.0.0\n * @example 2.5\n */\n speed: number | null;\n /**\n * Time the location was produced, in milliseconds since the unix epoch.\n * Use this to check if a location is stale when using stale: true.\n *\n * @since 7.0.0\n * @example 1640995200000\n */\n time: number | null;\n}\n\n/**\n * Error object that may be passed to the location start callback.\n * Extends the standard Error with optional error codes.\n *\n * @since 7.0.0\n */\nexport interface CallbackError extends Error {\n /**\n * Optional error code for more specific error handling.\n *\n * @since 7.0.0\n * @example \"PERMISSION_DENIED\"\n */\n code?: string;\n}\n\nexport interface SetPlannedRouteOptions {\n /**\n * The name of the sound file to play.\n * Must be a valid sound relative path in the app's public folder to work for both web and native platforms.\n * There's no need to include the public folder in the path.\n * @since 7.0.10\n * @example \"notification.mp3\"\n * */\n soundFile: string;\n /**\n * The planned route as an array of longitude and latitude pairs.\n * Each pair represents a point on the route.\n * This is used to define a route that the user can follow.\n * The route is used to play a sound when the user deviates from it.\n * @since 7.0.11\n * @example [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n */\n route: [number, number][];\n\n /**\n * The distance in meters that the user must deviate from the planned route to trigger the sound.\n * This is used to determine how far off the route the user can be before the sound is played.\n * If not specified, a default value of 50 meters is used.\n * @since 7.0.11\n * @default 50\n * @example 50\n */\n distance: number;\n}\n\n/**\n * Main plugin interface for background geolocation functionality.\n * Provides methods to manage location updates and access device settings.\n *\n * @since 7.0.0\n */\nexport interface BackgroundGeolocationPlugin {\n /**\n * To start listening for changes in the device's location, call this method.\n * A Promise is returned to indicate that it finished the call. The callback will be called every time a new location\n * is available, or if there was an error when calling this method. Don't rely on promise rejection for this.\n *\n * @param options The configuration options\n * @param callback The callback function invoked when a new location is available or an error occurs\n * @returns A promise that resolves when the method is successfully called\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.start(\n * {\n * backgroundMessage: \"App is using your location in the background\",\n * backgroundTitle: \"Location Service\",\n * requestPermissions: true,\n * stale: false,\n * distanceFilter: 10\n * },\n * (location, error) => {\n * if (error) {\n * console.error('Location error:', error);\n * return;\n * }\n * if (location) {\n * console.log('New location:', location.latitude, location.longitude);\n * }\n * }\n * );\n */\n start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void>;\n\n /**\n * Stops location updates.\n *\n * @returns A promise that resolves when the plugin stops successfully removed\n *\n * @since 7.0.9\n * @example\n * await BackgroundGeolocation.stop();\n */\n stop(): Promise<void>;\n\n /**\n * Opens the device's location settings page.\n * Useful for directing users to enable location services or adjust permissions.\n *\n * @returns A promise that resolves when the settings page is opened\n *\n * @since 7.0.0\n * @example\n * // Direct user to location settings\n * await BackgroundGeolocation.openSettings();\n */\n openSettings(): Promise<void>;\n\n /**\n * Plays a sound file when the user deviates from the planned route.\n * This should be used to play a sound (in the background too, only for native).\n *\n * @param options The options for setting the planned route and sound file\n * @returns A promise that resolves when the route is set successfully\n *\n * @since 7.0.11\n * @example\n * await BackgroundGeolocation.setPlannedRoute({\n * soundFile: \"notification.mp3\",\n * route: [[-74.0060, 40.7128], [-118.2437, 34.0522]]\n * });\n */\n setPlannedRoute(options: SetPlannedRouteOptions): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -15,4 +15,7 @@ export declare class BackgroundGeolocationWeb extends WebPlugin implements Backg
15
15
  private haversine;
16
16
  private distancePointToLineSegment;
17
17
  private distancePointToRoute;
18
+ getPluginVersion(): Promise<{
19
+ version: string;
20
+ }>;
18
21
  }
package/dist/esm/web.js CHANGED
@@ -145,6 +145,9 @@ export class BackgroundGeolocationWeb extends WebPlugin {
145
145
  }
146
146
  return minDistance;
147
147
  }
148
+ async getPluginVersion() {
149
+ return { version: 'web' };
150
+ }
148
151
  }
149
152
  BackgroundGeolocationWeb.EARTH_RADIUS_M = 6371000;
150
153
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IAAvD;;QAIU,iBAAY,GAAuB,EAAE,CAAC;QAEtC,eAAU,GAAG,IAAI,CAAC;QAClB,sBAAiB,GAAG,EAAE,CAAC;IA6KjC,CAAC;IA3KC,KAAK,CAAC,KAAK,CAAC,OAAqB,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I,QAAQ,GAAG,WAAW,EAAE,CAAC;gBAC3B,WAAW,GAAG,QAAQ,CAAC;YACzB,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;;AAlLuB,uCAAc,GAAG,OAAO,AAAV,CAAW","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n BackgroundGeolocationPlugin,\n StartOptions,\n Location,\n CallbackError,\n SetPlannedRouteOptions,\n} from './definitions';\n\nexport class BackgroundGeolocationWeb extends WebPlugin implements BackgroundGeolocationPlugin {\n private static readonly EARTH_RADIUS_M = 6371000;\n\n private watchId: number | undefined;\n private plannedRoute: [number, number][] = [];\n private audio: HTMLAudioElement | undefined;\n private isOffRoute = true;\n private distanceThreshold = 50;\n\n async start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void> {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation is not supported by this browser',\n code: 'NOT_SUPPORTED',\n });\n return;\n }\n\n if (this.watchId) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation already started',\n code: 'ALREADY_STARTED',\n });\n return;\n }\n\n this.watchId = navigator.geolocation.watchPosition(\n (position) => {\n const location: Location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n if (this.audio && this.plannedRoute.length > 0) {\n const currentPoint: [number, number] = [position.coords.longitude, position.coords.latitude];\n const offRoute = this.distancePointToRoute(currentPoint) > this.distanceThreshold;\n if (offRoute == true && this.isOffRoute === false) {\n this.audio.play();\n }\n this.isOffRoute = offRoute;\n }\n callback(location);\n },\n (error) => {\n const callbackError: CallbackError = {\n name: 'GeolocationError',\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n },\n {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n },\n );\n }\n\n async stop(): Promise<void> {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n\n async openSettings(): Promise<void> {\n console.log('openSettings: Web implementation cannot open native settings');\n window.alert('Please enable location permissions in your browser settings');\n }\n\n async setPlannedRoute(options: SetPlannedRouteOptions): Promise<void> {\n if (!options.soundFile) {\n throw new Error('Sound file is required');\n }\n if (this.audio) {\n this.audio.pause();\n this.audio.src = '';\n this.audio = undefined;\n }\n this.audio = new Audio(options.soundFile);\n this.plannedRoute = options.route || [];\n this.distanceThreshold = options.distance || 50;\n }\n\n private toRadians(degrees: number): number {\n return (degrees * Math.PI) / 180;\n }\n\n private haversine(point1: [number, number], point2: [number, number]): number {\n const [lon1, lat1] = point1;\n const [lon2, lat2] = point2;\n const dLat = this.toRadians(lat2 - lat1);\n const dLon = this.toRadians(lon2 - lon1);\n\n const a =\n Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);\n\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n return BackgroundGeolocationWeb.EARTH_RADIUS_M * c;\n }\n\n private distancePointToLineSegment(\n point: [number, number],\n lineStart: [number, number],\n lineEnd: [number, number],\n ): number {\n // Calculate the distances between the three points using Haversine\n const dist_A_B = this.haversine(point, lineStart);\n const dist_A_C = this.haversine(point, lineEnd);\n const dist_B_C = this.haversine(lineStart, lineEnd);\n\n // Handle the edge case where the line segment is a single point\n if (dist_B_C === 0) {\n return dist_A_B;\n }\n\n // Check if the angles at the line segment's endpoints are obtuse.\n // We use the Law of Cosines (c^2 = a^2 + b^2 - 2ab*cos(C))\n // If cos(C) < 0, the angle is obtuse.\n\n // Angle at B (lineStart)\n // Use a small epsilon to handle floating point inaccuracies in division by zero\n const cos_B = (dist_A_B ** 2 + dist_B_C ** 2 - dist_A_C ** 2) / (2 * dist_A_B * dist_B_C + Number.EPSILON);\n if (cos_B < 0) {\n return dist_A_B;\n }\n\n // Angle at C (lineEnd)\n const cos_C = (dist_A_C ** 2 + dist_B_C ** 2 - dist_A_B ** 2) / (2 * dist_A_C * dist_B_C + Number.EPSILON);\n if (cos_C < 0) {\n return dist_A_C;\n }\n\n // If both angles are acute, the closest point is on the line segment itself.\n // We can calculate the distance (height of the triangle) using its area.\n\n // 1. Calculate the semi-perimeter of the triangle ABC\n const s = (dist_A_B + dist_A_C + dist_B_C) / 2;\n\n // 2. Calculate the area using Heron's formula\n const area = Math.sqrt(Math.max(0, s * (s - dist_A_B) * (s - dist_A_C) * (s - dist_B_C)));\n\n // 3. The distance is the height of the triangle from point A to the base BC\n // Area = 0.5 * base * height => height = 2 * Area / base\n return (2 * area) / (dist_B_C + Number.EPSILON);\n }\n\n private distancePointToRoute(point: [number, number]): number {\n // If the route has less than 2 points, we can't form a segment.\n if (this.plannedRoute.length < 2) {\n if (this.plannedRoute.length === 1) {\n return this.haversine(point, this.plannedRoute[0]);\n }\n return Infinity; // No line segments to measure against\n }\n\n let minDistance = Infinity;\n\n for (let i = 0; i < this.plannedRoute.length - 1; i++) {\n const lineStart = this.plannedRoute[i];\n const lineEnd = this.plannedRoute[i + 1];\n const distance = this.distancePointToLineSegment(point, lineStart, lineEnd);\n if (distance < minDistance) {\n minDistance = distance;\n }\n }\n\n return minDistance;\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,wBAAyB,SAAQ,SAAS;IAAvD;;QAIU,iBAAY,GAAuB,EAAE,CAAC;QAEtC,eAAU,GAAG,IAAI,CAAC;QAClB,sBAAiB,GAAG,EAAE,CAAC;IAiLjC,CAAC;IA/KC,KAAK,CAAC,KAAK,CAAC,OAAqB,EAAE,QAA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GAAG,WAAW,EAAE,CAAC;gBAC3B,WAAW,GAAG,QAAQ,CAAC;YACzB,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;;AAtLuB,uCAAc,GAAG,OAAO,AAAV,CAAW","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n BackgroundGeolocationPlugin,\n StartOptions,\n Location,\n CallbackError,\n SetPlannedRouteOptions,\n} from './definitions';\n\nexport class BackgroundGeolocationWeb extends WebPlugin implements BackgroundGeolocationPlugin {\n private static readonly EARTH_RADIUS_M = 6371000;\n\n private watchId: number | undefined;\n private plannedRoute: [number, number][] = [];\n private audio: HTMLAudioElement | undefined;\n private isOffRoute = true;\n private distanceThreshold = 50;\n\n async start(options: StartOptions, callback: (position?: Location, error?: CallbackError) => void): Promise<void> {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation is not supported by this browser',\n code: 'NOT_SUPPORTED',\n });\n return;\n }\n\n if (this.watchId) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation already started',\n code: 'ALREADY_STARTED',\n });\n return;\n }\n\n this.watchId = navigator.geolocation.watchPosition(\n (position) => {\n const location: Location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n if (this.audio && this.plannedRoute.length > 0) {\n const currentPoint: [number, number] = [position.coords.longitude, position.coords.latitude];\n const offRoute = this.distancePointToRoute(currentPoint) > this.distanceThreshold;\n if (offRoute == true && this.isOffRoute === false) {\n this.audio.play();\n }\n this.isOffRoute = offRoute;\n }\n callback(location);\n },\n (error) => {\n const callbackError: CallbackError = {\n name: 'GeolocationError',\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n },\n {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n },\n );\n }\n\n async stop(): Promise<void> {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n\n async openSettings(): Promise<void> {\n console.log('openSettings: Web implementation cannot open native settings');\n window.alert('Please enable location permissions in your browser settings');\n }\n\n async setPlannedRoute(options: SetPlannedRouteOptions): Promise<void> {\n if (!options.soundFile) {\n throw new Error('Sound file is required');\n }\n if (this.audio) {\n this.audio.pause();\n this.audio.src = '';\n this.audio = undefined;\n }\n this.audio = new Audio(options.soundFile);\n this.plannedRoute = options.route || [];\n this.distanceThreshold = options.distance || 50;\n }\n\n private toRadians(degrees: number): number {\n return (degrees * Math.PI) / 180;\n }\n\n private haversine(point1: [number, number], point2: [number, number]): number {\n const [lon1, lat1] = point1;\n const [lon2, lat2] = point2;\n const dLat = this.toRadians(lat2 - lat1);\n const dLon = this.toRadians(lon2 - lon1);\n\n const a =\n Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);\n\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n return BackgroundGeolocationWeb.EARTH_RADIUS_M * c;\n }\n\n private distancePointToLineSegment(\n point: [number, number],\n lineStart: [number, number],\n lineEnd: [number, number],\n ): number {\n // Calculate the distances between the three points using Haversine\n const dist_A_B = this.haversine(point, lineStart);\n const dist_A_C = this.haversine(point, lineEnd);\n const dist_B_C = this.haversine(lineStart, lineEnd);\n\n // Handle the edge case where the line segment is a single point\n if (dist_B_C === 0) {\n return dist_A_B;\n }\n\n // Check if the angles at the line segment's endpoints are obtuse.\n // We use the Law of Cosines (c^2 = a^2 + b^2 - 2ab*cos(C))\n // If cos(C) < 0, the angle is obtuse.\n\n // Angle at B (lineStart)\n // Use a small epsilon to handle floating point inaccuracies in division by zero\n const cos_B = (dist_A_B ** 2 + dist_B_C ** 2 - dist_A_C ** 2) / (2 * dist_A_B * dist_B_C + Number.EPSILON);\n if (cos_B < 0) {\n return dist_A_B;\n }\n\n // Angle at C (lineEnd)\n const cos_C = (dist_A_C ** 2 + dist_B_C ** 2 - dist_A_B ** 2) / (2 * dist_A_C * dist_B_C + Number.EPSILON);\n if (cos_C < 0) {\n return dist_A_C;\n }\n\n // If both angles are acute, the closest point is on the line segment itself.\n // We can calculate the distance (height of the triangle) using its area.\n\n // 1. Calculate the semi-perimeter of the triangle ABC\n const s = (dist_A_B + dist_A_C + dist_B_C) / 2;\n\n // 2. Calculate the area using Heron's formula\n const area = Math.sqrt(Math.max(0, s * (s - dist_A_B) * (s - dist_A_C) * (s - dist_B_C)));\n\n // 3. The distance is the height of the triangle from point A to the base BC\n // Area = 0.5 * base * height => height = 2 * Area / base\n return (2 * area) / (dist_B_C + Number.EPSILON);\n }\n\n private distancePointToRoute(point: [number, number]): number {\n // If the route has less than 2 points, we can't form a segment.\n if (this.plannedRoute.length < 2) {\n if (this.plannedRoute.length === 1) {\n return this.haversine(point, this.plannedRoute[0]);\n }\n return Infinity; // No line segments to measure against\n }\n\n let minDistance = Infinity;\n\n for (let i = 0; i < this.plannedRoute.length - 1; i++) {\n const lineStart = this.plannedRoute[i];\n const lineEnd = this.plannedRoute[i + 1];\n const distance = this.distancePointToLineSegment(point, lineStart, lineEnd);\n if (distance < minDistance) {\n minDistance = distance;\n }\n }\n\n return minDistance;\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n}\n"]}
@@ -152,6 +152,9 @@ class BackgroundGeolocationWeb extends core.WebPlugin {
152
152
  }
153
153
  return minDistance;
154
154
  }
155
+ async getPluginVersion() {
156
+ return { version: 'web' };
157
+ }
155
158
  }
156
159
  BackgroundGeolocationWeb.EARTH_RADIUS_M = 6371000;
157
160
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundGeolocation = registerPlugin('BackgroundGeolocation', {\n web: () => import('./web').then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from './definitions';\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundGeolocationWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.plannedRoute = [];\n this.isOffRoute = true;\n this.distanceThreshold = 50;\n }\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation is not supported by this browser',\n code: 'NOT_SUPPORTED',\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation already started',\n code: 'ALREADY_STARTED',\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n if (this.audio && this.plannedRoute.length > 0) {\n const currentPoint = [position.coords.longitude, position.coords.latitude];\n const offRoute = this.distancePointToRoute(currentPoint) > this.distanceThreshold;\n if (offRoute == true && this.isOffRoute === false) {\n this.audio.play();\n }\n this.isOffRoute = offRoute;\n }\n callback(location);\n }, (error) => {\n const callbackError = {\n name: 'GeolocationError',\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log('openSettings: Web implementation cannot open native settings');\n window.alert('Please enable location permissions in your browser settings');\n }\n async setPlannedRoute(options) {\n if (!options.soundFile) {\n throw new Error('Sound file is required');\n }\n if (this.audio) {\n this.audio.pause();\n this.audio.src = '';\n this.audio = undefined;\n }\n this.audio = new Audio(options.soundFile);\n this.plannedRoute = options.route || [];\n this.distanceThreshold = options.distance || 50;\n }\n toRadians(degrees) {\n return (degrees * Math.PI) / 180;\n }\n haversine(point1, point2) {\n const [lon1, lat1] = point1;\n const [lon2, lat2] = point2;\n const dLat = this.toRadians(lat2 - lat1);\n const dLon = this.toRadians(lon2 - lon1);\n const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n return BackgroundGeolocationWeb.EARTH_RADIUS_M * c;\n }\n distancePointToLineSegment(point, lineStart, lineEnd) {\n // Calculate the distances between the three points using Haversine\n const dist_A_B = this.haversine(point, lineStart);\n const dist_A_C = this.haversine(point, lineEnd);\n const dist_B_C = this.haversine(lineStart, lineEnd);\n // Handle the edge case where the line segment is a single point\n if (dist_B_C === 0) {\n return dist_A_B;\n }\n // Check if the angles at the line segment's endpoints are obtuse.\n // We use the Law of Cosines (c^2 = a^2 + b^2 - 2ab*cos(C))\n // If cos(C) < 0, the angle is obtuse.\n // Angle at B (lineStart)\n // Use a small epsilon to handle floating point inaccuracies in division by zero\n const cos_B = (dist_A_B ** 2 + dist_B_C ** 2 - dist_A_C ** 2) / (2 * dist_A_B * dist_B_C + Number.EPSILON);\n if (cos_B < 0) {\n return dist_A_B;\n }\n // Angle at C (lineEnd)\n const cos_C = (dist_A_C ** 2 + dist_B_C ** 2 - dist_A_B ** 2) / (2 * dist_A_C * dist_B_C + Number.EPSILON);\n if (cos_C < 0) {\n return dist_A_C;\n }\n // If both angles are acute, the closest point is on the line segment itself.\n // We can calculate the distance (height of the triangle) using its area.\n // 1. Calculate the semi-perimeter of the triangle ABC\n const s = (dist_A_B + dist_A_C + dist_B_C) / 2;\n // 2. Calculate the area using Heron's formula\n const area = Math.sqrt(Math.max(0, s * (s - dist_A_B) * (s - dist_A_C) * (s - dist_B_C)));\n // 3. The distance is the height of the triangle from point A to the base BC\n // Area = 0.5 * base * height => height = 2 * Area / base\n return (2 * area) / (dist_B_C + Number.EPSILON);\n }\n distancePointToRoute(point) {\n // If the route has less than 2 points, we can't form a segment.\n if (this.plannedRoute.length < 2) {\n if (this.plannedRoute.length === 1) {\n return this.haversine(point, this.plannedRoute[0]);\n }\n return Infinity; // No line segments to measure against\n }\n let minDistance = Infinity;\n for (let i = 0; i < this.plannedRoute.length - 1; i++) {\n const lineStart = this.plannedRoute[i];\n const lineEnd = this.plannedRoute[i + 1];\n const distance = this.distancePointToLineSegment(point, lineStart, lineEnd);\n if (distance < minDistance) {\n minDistance = distance;\n }\n }\n return minDistance;\n }\n}\nBackgroundGeolocationWeb.EARTH_RADIUS_M = 6371000;\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;AACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;AAC5E,CAAC;;ACFM,MAAM,wBAAwB,SAASC,cAAS,CAAC;AACxD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE;AAC9B,QAAQ,IAAI,CAAC,UAAU,GAAG,IAAI;AAC9B,QAAQ,IAAI,CAAC,iBAAiB,GAAG,EAAE;AACnC,IAAI;AACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;AACnC,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;AACpC,YAAY,QAAQ,CAAC,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AAG,WAAW,EAAE;AACxC,gBAAgB,WAAW,GAAG,QAAQ;AACtC,YAAY;AACZ,QAAQ;AACR,QAAQ,OAAO,WAAW;AAC1B,IAAI;AACJ;AACA,wBAAwB,CAAC,cAAc,GAAG,OAAO;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundGeolocation = registerPlugin('BackgroundGeolocation', {\n web: () => import('./web').then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from './definitions';\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundGeolocationWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.plannedRoute = [];\n this.isOffRoute = true;\n this.distanceThreshold = 50;\n }\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation is not supported by this browser',\n code: 'NOT_SUPPORTED',\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation already started',\n code: 'ALREADY_STARTED',\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n if (this.audio && this.plannedRoute.length > 0) {\n const currentPoint = [position.coords.longitude, position.coords.latitude];\n const offRoute = this.distancePointToRoute(currentPoint) > this.distanceThreshold;\n if (offRoute == true && this.isOffRoute === false) {\n this.audio.play();\n }\n this.isOffRoute = offRoute;\n }\n callback(location);\n }, (error) => {\n const callbackError = {\n name: 'GeolocationError',\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log('openSettings: Web implementation cannot open native settings');\n window.alert('Please enable location permissions in your browser settings');\n }\n async setPlannedRoute(options) {\n if (!options.soundFile) {\n throw new Error('Sound file is required');\n }\n if (this.audio) {\n this.audio.pause();\n this.audio.src = '';\n this.audio = undefined;\n }\n this.audio = new Audio(options.soundFile);\n this.plannedRoute = options.route || [];\n this.distanceThreshold = options.distance || 50;\n }\n toRadians(degrees) {\n return (degrees * Math.PI) / 180;\n }\n haversine(point1, point2) {\n const [lon1, lat1] = point1;\n const [lon2, lat2] = point2;\n const dLat = this.toRadians(lat2 - lat1);\n const dLon = this.toRadians(lon2 - lon1);\n const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n return BackgroundGeolocationWeb.EARTH_RADIUS_M * c;\n }\n distancePointToLineSegment(point, lineStart, lineEnd) {\n // Calculate the distances between the three points using Haversine\n const dist_A_B = this.haversine(point, lineStart);\n const dist_A_C = this.haversine(point, lineEnd);\n const dist_B_C = this.haversine(lineStart, lineEnd);\n // Handle the edge case where the line segment is a single point\n if (dist_B_C === 0) {\n return dist_A_B;\n }\n // Check if the angles at the line segment's endpoints are obtuse.\n // We use the Law of Cosines (c^2 = a^2 + b^2 - 2ab*cos(C))\n // If cos(C) < 0, the angle is obtuse.\n // Angle at B (lineStart)\n // Use a small epsilon to handle floating point inaccuracies in division by zero\n const cos_B = (dist_A_B ** 2 + dist_B_C ** 2 - dist_A_C ** 2) / (2 * dist_A_B * dist_B_C + Number.EPSILON);\n if (cos_B < 0) {\n return dist_A_B;\n }\n // Angle at C (lineEnd)\n const cos_C = (dist_A_C ** 2 + dist_B_C ** 2 - dist_A_B ** 2) / (2 * dist_A_C * dist_B_C + Number.EPSILON);\n if (cos_C < 0) {\n return dist_A_C;\n }\n // If both angles are acute, the closest point is on the line segment itself.\n // We can calculate the distance (height of the triangle) using its area.\n // 1. Calculate the semi-perimeter of the triangle ABC\n const s = (dist_A_B + dist_A_C + dist_B_C) / 2;\n // 2. Calculate the area using Heron's formula\n const area = Math.sqrt(Math.max(0, s * (s - dist_A_B) * (s - dist_A_C) * (s - dist_B_C)));\n // 3. The distance is the height of the triangle from point A to the base BC\n // Area = 0.5 * base * height => height = 2 * Area / base\n return (2 * area) / (dist_B_C + Number.EPSILON);\n }\n distancePointToRoute(point) {\n // If the route has less than 2 points, we can't form a segment.\n if (this.plannedRoute.length < 2) {\n if (this.plannedRoute.length === 1) {\n return this.haversine(point, this.plannedRoute[0]);\n }\n return Infinity; // No line segments to measure against\n }\n let minDistance = Infinity;\n for (let i = 0; i < this.plannedRoute.length - 1; i++) {\n const lineStart = this.plannedRoute[i];\n const lineEnd = this.plannedRoute[i + 1];\n const distance = this.distancePointToLineSegment(point, lineStart, lineEnd);\n if (distance < minDistance) {\n minDistance = distance;\n }\n }\n return minDistance;\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\nBackgroundGeolocationWeb.EARTH_RADIUS_M = 6371000;\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;AACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;AAC5E,CAAC;;ACFM,MAAM,wBAAwB,SAASC,cAAS,CAAC;AACxD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE;AAC9B,QAAQ,IAAI,CAAC,UAAU,GA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AAClD,YAAY,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC;AACpD,YAAY,MAAM,QAAQ,GAAG,IAAI,CAAC,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;AACvF,YAAY,IAAI,QAAQ,GAAG,WAAW,EAAE;AACxC,gBAAgB,WAAW,GAAG,QAAQ;AACtC,YAAY;AACZ,QAAQ;AACR,QAAQ,OAAO,WAAW;AAC1B,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;AACA,wBAAwB,CAAC,cAAc,GAAG,OAAO;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -151,6 +151,9 @@ var capacitorBackgroundGeolocation = (function (exports, core) {
151
151
  }
152
152
  return minDistance;
153
153
  }
154
+ async getPluginVersion() {
155
+ return { version: 'web' };
156
+ }
154
157
  }
155
158
  BackgroundGeolocationWeb.EARTH_RADIUS_M = 6371000;
156
159
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundGeolocation = registerPlugin('BackgroundGeolocation', {\n web: () => import('./web').then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from './definitions';\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundGeolocationWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.plannedRoute = [];\n this.isOffRoute = true;\n this.distanceThreshold = 50;\n }\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation is not supported by this browser',\n code: 'NOT_SUPPORTED',\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation already started',\n code: 'ALREADY_STARTED',\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n if (this.audio && this.plannedRoute.length > 0) {\n const currentPoint = [position.coords.longitude, position.coords.latitude];\n const offRoute = this.distancePointToRoute(currentPoint) > this.distanceThreshold;\n if (offRoute == true && this.isOffRoute === false) {\n this.audio.play();\n }\n this.isOffRoute = offRoute;\n }\n callback(location);\n }, (error) => {\n const callbackError = {\n name: 'GeolocationError',\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log('openSettings: Web implementation cannot open native settings');\n window.alert('Please enable location permissions in your browser settings');\n }\n async setPlannedRoute(options) {\n if (!options.soundFile) {\n throw new Error('Sound file is required');\n }\n if (this.audio) {\n this.audio.pause();\n this.audio.src = '';\n this.audio = undefined;\n }\n this.audio = new Audio(options.soundFile);\n this.plannedRoute = options.route || [];\n this.distanceThreshold = options.distance || 50;\n }\n toRadians(degrees) {\n return (degrees * Math.PI) / 180;\n }\n haversine(point1, point2) {\n const [lon1, lat1] = point1;\n const [lon2, lat2] = point2;\n const dLat = this.toRadians(lat2 - lat1);\n const dLon = this.toRadians(lon2 - lon1);\n const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n return BackgroundGeolocationWeb.EARTH_RADIUS_M * c;\n }\n distancePointToLineSegment(point, lineStart, lineEnd) {\n // Calculate the distances between the three points using Haversine\n const dist_A_B = this.haversine(point, lineStart);\n const dist_A_C = this.haversine(point, lineEnd);\n const dist_B_C = this.haversine(lineStart, lineEnd);\n // Handle the edge case where the line segment is a single point\n if (dist_B_C === 0) {\n return dist_A_B;\n }\n // Check if the angles at the line segment's endpoints are obtuse.\n // We use the Law of Cosines (c^2 = a^2 + b^2 - 2ab*cos(C))\n // If cos(C) < 0, the angle is obtuse.\n // Angle at B (lineStart)\n // Use a small epsilon to handle floating point inaccuracies in division by zero\n const cos_B = (dist_A_B ** 2 + dist_B_C ** 2 - dist_A_C ** 2) / (2 * dist_A_B * dist_B_C + Number.EPSILON);\n if (cos_B < 0) {\n return dist_A_B;\n }\n // Angle at C (lineEnd)\n const cos_C = (dist_A_C ** 2 + dist_B_C ** 2 - dist_A_B ** 2) / (2 * dist_A_C * dist_B_C + Number.EPSILON);\n if (cos_C < 0) {\n return dist_A_C;\n }\n // If both angles are acute, the closest point is on the line segment itself.\n // We can calculate the distance (height of the triangle) using its area.\n // 1. Calculate the semi-perimeter of the triangle ABC\n const s = (dist_A_B + dist_A_C + dist_B_C) / 2;\n // 2. Calculate the area using Heron's formula\n const area = Math.sqrt(Math.max(0, s * (s - dist_A_B) * (s - dist_A_C) * (s - dist_B_C)));\n // 3. The distance is the height of the triangle from point A to the base BC\n // Area = 0.5 * base * height => height = 2 * Area / base\n return (2 * area) / (dist_B_C + Number.EPSILON);\n }\n distancePointToRoute(point) {\n // If the route has less than 2 points, we can't form a segment.\n if (this.plannedRoute.length < 2) {\n if (this.plannedRoute.length === 1) {\n return this.haversine(point, this.plannedRoute[0]);\n }\n return Infinity; // No line segments to measure against\n }\n let minDistance = Infinity;\n for (let i = 0; i < this.plannedRoute.length - 1; i++) {\n const lineStart = this.plannedRoute[i];\n const lineEnd = this.plannedRoute[i + 1];\n const distance = this.distancePointToLineSegment(point, lineStart, lineEnd);\n if (distance < minDistance) {\n minDistance = distance;\n }\n }\n return minD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GAAG,CAAC,EAAE;IAC1C,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;IAChD,gBAAgB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAClE,YAAY;IACZ,YAAY,OAAO,QAAQ,CAAC;IAC5B,QAAQ;IACR,QAAQ,IAAI,WAAW,GAAG,QAAQ;IAClC,QAAQ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;IAC/D,YAAY,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAClD,YAAY,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC;IACpD,YAAY,MAAM,QAAQ,GAAG,IAAI,CAAC,0BAA0B,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;IACvF,YAAY,IAAI,QAAQ,GAAG,WAAW,EAAE;IACxC,gBAAgB,WAAW,GAAG,QAAQ;IACtC,YAAY;IACZ,QAAQ;IACR,QAAQ,OAAO,WAAW;IAC1B,IAAI;IACJ;IACA,wBAAwB,CAAC,cAAc,GAAG,OAAO;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst BackgroundGeolocation = registerPlugin('BackgroundGeolocation', {\n web: () => import('./web').then((m) => new m.BackgroundGeolocationWeb()),\n});\nexport * from './definitions';\nexport { BackgroundGeolocation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class BackgroundGeolocationWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.plannedRoute = [];\n this.isOffRoute = true;\n this.distanceThreshold = 50;\n }\n async start(options, callback) {\n if (!navigator.geolocation) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation is not supported by this browser',\n code: 'NOT_SUPPORTED',\n });\n return;\n }\n if (this.watchId) {\n callback(undefined, {\n name: 'GeolocationError',\n message: 'Geolocation already started',\n code: 'ALREADY_STARTED',\n });\n return;\n }\n this.watchId = navigator.geolocation.watchPosition((position) => {\n const location = {\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n altitude: position.coords.altitude,\n altitudeAccuracy: position.coords.altitudeAccuracy,\n simulated: false,\n bearing: position.coords.heading,\n speed: position.coords.speed,\n time: position.timestamp,\n };\n if (this.audio && this.plannedRoute.length > 0) {\n const currentPoint = [position.coords.longitude, position.coords.latitude];\n const offRoute = this.distancePointToRoute(currentPoint) > this.distanceThreshold;\n if (offRoute == true && this.isOffRoute === false) {\n this.audio.play();\n }\n this.isOffRoute = offRoute;\n }\n callback(location);\n }, (error) => {\n const callbackError = {\n name: 'GeolocationError',\n message: error.message,\n code: error.code.toString(),\n };\n callback(undefined, callbackError);\n }, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: options.stale ? 300000 : 0,\n });\n }\n async stop() {\n if (this.watchId) {\n navigator.geolocation.clearWatch(this.watchId);\n delete this.watchId;\n }\n }\n async openSettings() {\n console.log('openSettings: Web implementation cannot open native settings');\n window.alert('Please enable location permissions in your browser settings');\n }\n async setPlannedRoute(options) {\n if (!options.soundFile) {\n throw new Error('Sound file is required');\n }\n if (this.audio) {\n this.audio.pause();\n this.audio.src = '';\n this.audio = undefined;\n }\n this.audio = new Audio(options.soundFile);\n this.plannedRoute = options.route || [];\n this.distanceThreshold = options.distance || 50;\n }\n toRadians(degrees) {\n return (degrees * Math.PI) / 180;\n }\n haversine(point1, point2) {\n const [lon1, lat1] = point1;\n const [lon2, lat2] = point2;\n const dLat = this.toRadians(lat2 - lat1);\n const dLon = this.toRadians(lon2 - lon1);\n const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +\n Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);\n const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n return BackgroundGeolocationWeb.EARTH_RADIUS_M * c;\n }\n distancePointToLineSegment(point, lineStart, lineEnd) {\n // Calculate the distances between the three points using Haversine\n const dist_A_B = this.haversine(point, lineStart);\n const dist_A_C = this.haversine(point, lineEnd);\n const dist_B_C = this.haversine(lineStart, lineEnd);\n // Handle the edge case where the line segment is a single point\n if (dist_B_C === 0) {\n return dist_A_B;\n }\n // Check if the angles at the line segment's endpoints are obtuse.\n // We use the Law of Cosines (c^2 = a^2 + b^2 - 2ab*cos(C))\n // If cos(C) < 0, the angle is obtuse.\n // Angle at B (lineStart)\n // Use a small epsilon to handle floating point inaccuracies in division by zero\n const cos_B = (dist_A_B ** 2 + dist_B_C ** 2 - dist_A_C ** 2) / (2 * dist_A_B * dist_B_C + Number.EPSILON);\n if (cos_B < 0) {\n return dist_A_B;\n }\n // Angle at C (lineEnd)\n const cos_C = (dist_A_C ** 2 + dist_B_C ** 2 - dist_A_B ** 2) / (2 * dist_A_C * dist_B_C + Number.EPSILON);\n if (cos_C < 0) {\n return dist_A_C;\n }\n // If both angles are acute, the closest point is on the line segment itself.\n // We can calculate the distance (height of the triangle) using its area.\n // 1. Calculate the semi-perimeter of the triangle ABC\n const s = (dist_A_B + dist_A_C + dist_B_C) / 2;\n // 2. Calculate the area using Heron's formula\n const area = Math.sqrt(Math.max(0, s * (s - dist_A_B) * (s - dist_A_C) * (s - dist_B_C)));\n // 3. The distance is the height of the triangle from point A to the base BC\n // Area = 0.5 * base * height => height = 2 * Area / base\n return (2 * area) / (dist_B_C + Number.EPSILON);\n }\n distancePointToRoute(point) {\n // If the route has less than 2 points, we can't form a segment.\n if (this.plannedRoute.length < 2) {\n if (this.plannedRoute.length === 1) {\n return this.haversine(point, this.plannedRoute[0]);\n }\n return Infinity; // No line segments to measure against\n }\n let minDistance = Infinity;\n for (let i = 0; i < this.plannedRoute.length - 1; i++) {\n const lineStart = this.plannedRoute[i];\n const lineEnd = this.plannedRoute[i + 1];\n const distance = this.distancePointToLineSegment(point, lineStart, lineEnd);\n if (distance < minDistance) {\n minDistance = distance;\n }\n }\n return minDistance;\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\nBackgroundGeolocationWeb.EARTH_RADIUS_M = 6371000;\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,qBAAqB,GAAGA,mBAAc,CAAC,uBAAuB,EAAE;IACtE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IAC5E,CAAC;;ICFM,MAAM,wBAAwB,SAASC,cAAS,CAAC;IACxD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE;IAC9B,QAAQ,IAAI,CAAC,UAAU,GAAG,IAAI;IAC9B,QAAQ,IAAI,CAAC,iBAAiB,GAAG,EAAE;IACnC,IAAI;IACJ,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE;IACnC,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;IACpC,YAAY,QAAQ,CAAC,SAAS,EAAE;IAChC,gBAAgB,IAAI,EAAE,kBAAkB;IACxC,gBAAgB,OAAO,EAAE,8CAA8C;IACvE,gBAAgB,IAAI,EAAE,eAAe;IACrC,aAAa,CAAC;IACd,YAAY;IACZ,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;IAC1B,YAAY,QAAQ,CAAC,SAAS,EAAE;IAChC,gBAAgB,IAAI,EAAE,kBAAkB;IACxC,gBAAgB,OAAO,EAAE,6BAA6B;IACtD,gBAAgB,IAAI,EAAE,iBAAiB;IACvC,aAAa,CAAC;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
38
  public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBridgedPlugin {
39
+ private let PLUGIN_VERSION: String = "7.1.0"
39
40
  public let identifier = "BackgroundGeolocationPlugin"
40
41
  public let jsName = "BackgroundGeolocation"
41
42
  public let pluginMethods: [CAPPluginMethod] = [
42
43
  CAPPluginMethod(name: "start", returnType: CAPPluginReturnPromise),
43
44
  CAPPluginMethod(name: "stop", returnType: CAPPluginReturnPromise),
44
45
  CAPPluginMethod(name: "openSettings", returnType: CAPPluginReturnPromise),
45
- CAPPluginMethod(name: "setPlannedRoute", returnType: CAPPluginReturnPromise)
46
+ CAPPluginMethod(name: "setPlannedRoute", returnType: CAPPluginReturnPromise),
47
+ CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
46
48
  ]
47
49
  private var locationManager: CLLocationManager?
48
50
  private var created: Date?
@@ -383,4 +385,9 @@ public class BackgroundGeolocation: CAPPlugin, CLLocationManagerDelegate, CAPBri
383
385
  startUpdatingLocation()
384
386
  }
385
387
  }
388
+
389
+ @objc func getPluginVersion(_ call: CAPPluginCall) {
390
+ call.resolve(["version": self.PLUGIN_VERSION])
391
+ }
392
+
386
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/background-geolocation",
3
- "version": "7.0.20",
3
+ "version": "7.1.0",
4
4
  "description": "Receive accurate geolocation updates even while the app is in the background.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",