@azatek/background-geolocation 1.0.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.
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorCommunityBackgroundGeolocation'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '12.0'
15
+ s.dependency 'Capacitor'
16
+ end
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright 2021 James Diacono
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/Package.swift ADDED
@@ -0,0 +1,29 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapacitorCommunityBackgroundGeolocation",
6
+ platforms: [.iOS(.v12)],
7
+ products: [
8
+ .library(
9
+ name: "CapacitorCommunityBackgroundGeolocation",
10
+ targets: ["BackgroundGeolocationPlugin"]
11
+ )
12
+ ],
13
+ dependencies: [
14
+ .package(
15
+ url: "https://github.com/ionic-team/capacitor-swift-pm.git",
16
+ from: "7.0.0"
17
+ )
18
+ ],
19
+ targets: [
20
+ .target(
21
+ name: "BackgroundGeolocationPlugin",
22
+ dependencies: [
23
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
24
+ .product(name: "Cordova", package: "capacitor-swift-pm")
25
+ ],
26
+ path: "ios/Plugin/Swift"
27
+ )
28
+ ]
29
+ )
package/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # @azatek/background-geolocation
2
+
3
+ Enhanced fork of [@capacitor-community/background-geolocation](https://github.com/capacitor-community/background-geolocation) with configurable GPS accuracy modes for battery optimization.
4
+
5
+ ## Additional Features
6
+
7
+ - **Configurable GPS Accuracy**: Choose between HIGH, BALANCED, LOW, and PASSIVE modes
8
+ - **Battery Optimization**: Dynamically switch accuracy based on proximity to points of interest
9
+ - **Android Priority Support**: Uses modern LocationRequest.Builder with Priority levels
10
+ - **iOS Accuracy Control**: Configurable CLLocationManager accuracy settings
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @azatek/background-geolocation
16
+ npx cap update
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import { BackgroundGeolocation, LocationAccuracy } from '@azatek/background-geolocation';
23
+
24
+ const watcherId = await BackgroundGeolocation.addWatcher({
25
+ backgroundMessage: "Tracking location",
26
+ backgroundTitle: "App Active",
27
+ requestPermissions: true,
28
+ stale: false,
29
+ distanceFilter: 50,
30
+ accuracy: LocationAccuracy.BALANCED // NEW: Accuracy control
31
+ }, (location) => {
32
+ console.log(location);
33
+ });
34
+ ```
35
+
36
+ ## Accuracy Modes
37
+
38
+ - **LocationAccuracy.HIGH (100)**: GPS only - High battery usage, best accuracy
39
+ - **LocationAccuracy.BALANCED (102)**: GPS + Network - Medium battery, good accuracy
40
+ - **LocationAccuracy.LOW (104)**: Network only - Low battery, approximate location
41
+ - **LocationAccuracy.PASSIVE (105)**: Minimal battery, uses other apps' location requests
42
+
43
+ ## Original Usage
44
+
45
+ ```javascript
46
+ import {registerPlugin} from "@capacitor/core";
47
+ const BackgroundGeolocation = registerPlugin("BackgroundGeolocation");
48
+
49
+ // To start listening for changes in the device's location, add a new watcher.
50
+ // You do this by calling 'addWatcher' with an options object and a callback. A
51
+ // Promise is returned, which resolves to the callback ID used to remove the
52
+ // watcher in the future. The callback will be called every time a new location
53
+ // is available. Watchers can not be paused, only removed. Multiple watchers may
54
+ // exist simultaneously.
55
+ BackgroundGeolocation.addWatcher(
56
+ {
57
+ // If the "backgroundMessage" option is defined, the watcher will
58
+ // provide location updates whether the app is in the background or the
59
+ // foreground. If it is not defined, location updates are only
60
+ // guaranteed in the foreground. This is true on both platforms.
61
+
62
+ // On Android, a notification must be shown to continue receiving
63
+ // location updates in the background. This option specifies the text of
64
+ // that notification.
65
+ backgroundMessage: "Cancel to prevent battery drain.",
66
+
67
+ // The title of the notification mentioned above. Defaults to "Using
68
+ // your location".
69
+ backgroundTitle: "Tracking You.",
70
+
71
+ // Whether permissions should be requested from the user automatically,
72
+ // if they are not already granted. Defaults to "true".
73
+ requestPermissions: true,
74
+
75
+ // If "true", stale locations may be delivered while the device
76
+ // obtains a GPS fix. You are responsible for checking the "time"
77
+ // property. If "false", locations are guaranteed to be up to date.
78
+ // Defaults to "false".
79
+ stale: false,
80
+
81
+ // The minimum number of metres between subsequent locations. Defaults
82
+ // to 0.
83
+ distanceFilter: 50
84
+ },
85
+ function callback(location, error) {
86
+ if (error) {
87
+ if (error.code === "NOT_AUTHORIZED") {
88
+ if (window.confirm(
89
+ "This app needs your location, " +
90
+ "but does not have permission.\n\n" +
91
+ "Open settings now?"
92
+ )) {
93
+ // It can be useful to direct the user to their device's
94
+ // settings when location permissions have been denied. The
95
+ // plugin provides the 'openSettings' method to do exactly
96
+ // this.
97
+ BackgroundGeolocation.openSettings();
98
+ }
99
+ }
100
+ return console.error(error);
101
+ }
102
+
103
+ return console.log(location);
104
+ }
105
+ ).then(function after_the_watcher_has_been_added(watcher_id) {
106
+ // When a watcher is no longer needed, it should be removed by calling
107
+ // 'removeWatcher' with an object containing its ID.
108
+ BackgroundGeolocation.removeWatcher({
109
+ id: watcher_id
110
+ });
111
+ });
112
+
113
+ // The location object.
114
+ {
115
+ // Longitude in degrees.
116
+ longitude: 131.723423719132,
117
+ // Latitude in degrees.
118
+ latitude: -22.40106297456,
119
+ // Radius of horizontal uncertainty in metres, with 68% confidence.
120
+ accuracy: 11,
121
+ // Metres above sea level (or null).
122
+ altitude: 65,
123
+ // Vertical uncertainty in metres, with 68% confidence (or null).
124
+ altitudeAccuracy: 4,
125
+ // Deviation from true north in degrees (or null).
126
+ bearing: 159.60000610351562,
127
+ // True if the location was simulated by software, rather than GPS.
128
+ simulated: false,
129
+ // Speed in metres per second (or null).
130
+ speed: 23.51068878173828,
131
+ // Time the location was produced, in milliseconds since the unix epoch.
132
+ time: 1562731602000
133
+ }
134
+
135
+ // If you just want the current location, try something like this. The longer
136
+ // the timeout, the more accurate the guess will be. I wouldn't go below about
137
+ // 100ms.
138
+ function guess_location(callback, timeout) {
139
+ let last_location;
140
+ BackgroundGeolocation.addWatcher(
141
+ {
142
+ requestPermissions: false,
143
+ stale: true
144
+ },
145
+ function (location) {
146
+ last_location = location || undefined;
147
+ }
148
+ ).then(function (id) {
149
+ setTimeout(function () {
150
+ callback(last_location);
151
+ Plugins.BackgroundGeolocation.removeWatcher({id});
152
+ }, timeout);
153
+ });
154
+ }
155
+ ```
156
+
157
+ ### Typescript support
158
+
159
+ ```typescript
160
+ import {BackgroundGeolocationPlugin} from "@azatek/background-geolocation";
161
+ const BackgroundGeolocation = registerPlugin<BackgroundGeolocationPlugin>("BackgroundGeolocation");
162
+ ```
163
+
164
+ ## Version Compatibility
165
+
166
+ | Capacitor | Plugin |
167
+ |------------|--------|
168
+ | v7 | v1.3+ |
169
+
170
+ ### iOS
171
+ Add the following keys to `Info.plist.`:
172
+
173
+ ```xml
174
+ <dict>
175
+ ...
176
+ <key>NSLocationWhenInUseUsageDescription</key>
177
+ <string>We need to track your location</string>
178
+ <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
179
+ <string>We need to track your location while your device is locked.</string>
180
+ <key>UIBackgroundModes</key>
181
+ <array>
182
+ <string>location</string>
183
+ </array>
184
+ ...
185
+ </dict>
186
+ ```
187
+
188
+ ### Android
189
+
190
+ Set the the `android.useLegacyBridge` option to `true` in your Capacitor configuration. This prevents location updates halting after 5 minutes in the background. See https://capacitorjs.com/docs/config and https://github.com/capacitor-community/background-geolocation/issues/89.
191
+
192
+ On Android 13+, the app needs the `POST_NOTIFICATIONS` runtime permission to show the persistent notification informing the user that their location is being used in the background. You may need to [request this permission](https://developer.android.com/develop/ui/views/notifications/notification-permission) from the user, this can be accomplished [using the `@capacitor/local-notifications` plugin](https://capacitorjs.com/docs/apis/local-notifications#checkpermissions).
193
+
194
+ If your app forwards location updates to a server in real time, be aware that after 5 minutes in the background Android will throttle HTTP requests initiated from the WebView. The solution is to use a native HTTP plugin such as [CapacitorHttp](https://capacitorjs.com/docs/apis/http). See https://github.com/capacitor-community/background-geolocation/issues/14.
195
+
196
+ Configration specific to Android can be made in `strings.xml`:
197
+ ```xml
198
+ <resources>
199
+ <!--
200
+ The channel name for the background notification. This will be visible
201
+ when the user presses & holds the notification. It defaults to
202
+ "Background Tracking".
203
+ -->
204
+ <string name="capacitor_background_geolocation_notification_channel_name">
205
+ Background Tracking
206
+ </string>
207
+
208
+ <!--
209
+ The icon to use for the background notification. Note the absence of a
210
+ leading "@". It defaults to "mipmap/ic_launcher", the app's launch icon.
211
+
212
+ If a raster image is used to generate the icon (as opposed to a vector
213
+ image), it must have a transparent background. To make sure your image
214
+ is compatible, select "Notification Icons" as the Icon Type when
215
+ creating the image asset in Android Studio.
216
+
217
+ An incompatible image asset will cause the notification to misbehave in
218
+ a few telling ways, even if the icon appears correctly:
219
+
220
+ - The notification may be dismissable by the user when it should not
221
+ be.
222
+ - Tapping the notification may open the settings, not the app.
223
+ - The notification text may be incorrect.
224
+ -->
225
+ <string name="capacitor_background_geolocation_notification_icon">
226
+ drawable/ic_tracking
227
+ </string>
228
+
229
+ <!--
230
+ The color of the notification as a string parseable by
231
+ android.graphics.Color.parseColor. Optional.
232
+ -->
233
+ <string name="capacitor_background_geolocation_notification_color">
234
+ yellow
235
+ </string>
236
+ </resources>
237
+
238
+ ```
239
+
240
+ ## Credits
241
+
242
+ Based on [@capacitor-community/background-geolocation](https://github.com/capacitor-community/background-geolocation)
@@ -0,0 +1,51 @@
1
+ ext {
2
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
3
+ androidxLocalbroadcastmanagerVersion = project.hasProperty('androidxLocalbroadcastmanagerVersion') ? rootProject.ext.androidxLocalbroadcastmanagerVersion : '1.0.0'
4
+ playServicesLocationVersion = project.hasProperty('playServicesLocationVersion') ? rootProject.ext.playServicesLocationVersion : '21.0.1'
5
+ }
6
+
7
+ buildscript {
8
+ repositories {
9
+ google()
10
+ mavenCentral()
11
+ }
12
+ dependencies {
13
+ classpath 'com.android.tools.build:gradle:8.0.0'
14
+ }
15
+ }
16
+
17
+ apply plugin: 'com.android.library'
18
+
19
+ android {
20
+ namespace "com.equimaps.capacitor_background_geolocation"
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
22
+ defaultConfig {
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
25
+ versionCode 1
26
+ versionName "1.0"
27
+ }
28
+ buildTypes {
29
+ release {
30
+ minifyEnabled false
31
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
32
+ }
33
+ }
34
+ lintOptions {
35
+ abortOnError false
36
+ }
37
+ }
38
+
39
+ repositories {
40
+ google()
41
+ mavenCentral()
42
+ }
43
+
44
+
45
+ dependencies {
46
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
47
+ implementation project(':capacitor-android')
48
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
49
+ implementation "androidx.localbroadcastmanager:localbroadcastmanager:$androidxLocalbroadcastmanagerVersion"
50
+ implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"
51
+ }
@@ -0,0 +1,6 @@
1
+ #Fri Dec 01 12:41:00 CST 2017
2
+ distributionBase=GRADLE_USER_HOME
3
+ distributionPath=wrapper/dists
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
6
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
@@ -0,0 +1,20 @@
1
+ # Project-wide Gradle settings.
2
+
3
+ # IDE (e.g. Android Studio) users:
4
+ # Gradle settings configured through the IDE *will override*
5
+ # any settings specified in this file.
6
+
7
+ # For more details on how to configure your build environment visit
8
+ # http://www.gradle.org/docs/current/userguide/build_environment.html
9
+
10
+ # Specifies the JVM arguments used for the daemon process.
11
+ # The setting is particularly useful for tweaking memory settings.
12
+ org.gradle.jvmargs=-Xmx1536m
13
+
14
+ # When configured, Gradle will run in incubating parallel mode.
15
+ # This option should only be used with decoupled projects. More details, visit
16
+ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17
+ # org.gradle.parallel=true
18
+
19
+ # Supports AndroidX
20
+ android.useAndroidX=true
@@ -0,0 +1,21 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile
@@ -0,0 +1,2 @@
1
+ include ':capacitor-android'
2
+ project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
@@ -0,0 +1,21 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <application>
3
+ <service
4
+ android:name="com.equimaps.capacitor_background_geolocation.BackgroundGeolocationService"
5
+ android:enabled="true"
6
+ android:exported="true"
7
+ android:foregroundServiceType="location" />
8
+ </application>
9
+
10
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
11
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
12
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
13
+ <!-- Android SDK 34+ additionally requires the FOREGROUND_SERVICE_LOCATION
14
+ runtime permission to start a foreground service of type "location". -->
15
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
16
+ <!-- Android SDK 33+ requires the POST_NOTIFICATIONS runtime permission to
17
+ display the foreground service notification. -->
18
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
19
+ <uses-feature android:name="android.hardware.location.gps" />
20
+ </manifest>
21
+