@azatek/background-geolocation 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,10 +35,31 @@ const watcherId = await BackgroundGeolocation.addWatcher({
35
35
 
36
36
  ## Accuracy Modes
37
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
38
+ | Mode | Value | Description | Accuracy Level |
39
+ |------|-------|-------------|----------------|
40
+ | **HIGH** | 100 | Best accuracy, high battery usage | Android: PRIORITY_HIGH_ACCURACY<br>iOS: kCLLocationAccuracyBest |
41
+ | **BALANCED** | 102 | Good accuracy (default) | Android: PRIORITY_BALANCED_POWER_ACCURACY<br>iOS: kCLLocationAccuracyNearestTenMeters |
42
+ | **LOW** | 104 | Approximate location | Android: PRIORITY_LOW_POWER<br>iOS: kCLLocationAccuracyHundredMeters |
43
+ | **PASSIVE** | 105 | Minimal battery | Android: PRIORITY_PASSIVE<br>iOS: kCLLocationAccuracyThreeKilometers |
44
+
45
+ ### Platform Behavior
46
+
47
+ **Both platforms now behave identically:**
48
+ - Location updates are triggered **only by distance changes**, not time intervals
49
+ - `distanceFilter: 50` → Updates only when device moves 50+ meters
50
+ - `distanceFilter: 0` → Updates on any movement (controlled by accuracy setting)
51
+
52
+ **Important:**
53
+ - ⚠️ With `distanceFilter > 0`, you will **NOT** receive updates when stationary
54
+ - ✅ This matches iOS behavior and saves battery
55
+ - 💡 Set `distanceFilter: 0` if you need updates even when stationary
56
+
57
+ **Android-specific:**
58
+ - Uses `FusedLocationProviderClient` with very large time interval to effectively disable time-based updates
59
+
60
+ **iOS-specific:**
61
+ - Uses `CLLocationManager.distanceFilter` natively
62
+ - HIGH mode automatically switches to `kCLLocationAccuracyBestForNavigation` when device is charging
42
63
 
43
64
  ## Original Usage
44
65
 
@@ -85,45 +85,38 @@ public class BackgroundGeolocationService extends Service {
85
85
 
86
86
  // Map accuracy enum to Android Priority
87
87
  int priority;
88
- long interval;
89
-
88
+
90
89
  switch (accuracy) {
91
90
  case 100: // HIGH
92
91
  priority = Priority.PRIORITY_HIGH_ACCURACY;
93
- interval = 5000; // 5 seconds
94
92
  break;
95
93
  case 102: // BALANCED (Default)
96
94
  priority = Priority.PRIORITY_BALANCED_POWER_ACCURACY;
97
- interval = 10000; // 10 seconds
98
95
  break;
99
96
  case 104: // LOW
100
97
  priority = Priority.PRIORITY_LOW_POWER;
101
- interval = 30000; // 30 seconds
102
98
  break;
103
99
  case 105: // PASSIVE
104
100
  priority = Priority.PRIORITY_PASSIVE;
105
- interval = 60000; // 60 seconds
106
101
  break;
107
102
  default:
108
103
  priority = Priority.PRIORITY_BALANCED_POWER_ACCURACY;
109
- interval = 10000;
110
104
  }
111
-
112
- // Use modern LocationRequest.Builder API
105
+
106
+ // Match iOS behavior: Only update based on distance, not time intervals
107
+ // When distanceFilter is 0, use a minimal interval to get updates
108
+ // When distanceFilter > 0, use a very large interval so only distance triggers updates
109
+ long interval = (distanceFilter > 0) ? Long.MAX_VALUE : 1000;
110
+
113
111
  LocationRequest locationRequest = new LocationRequest.Builder(priority, interval)
114
112
  .setMinUpdateDistanceMeters(distanceFilter)
115
113
  .setWaitForAccurateLocation(false)
116
- .setMaxUpdateDelayMillis(interval)
117
114
  .build();
118
115
 
119
116
  LocationCallback callback = new LocationCallback(){
120
117
  @Override
121
118
  public void onLocationResult(LocationResult locationResult) {
122
- Logger.debug("onLocationResult called");
123
119
  Location location = locationResult.getLastLocation();
124
- if (location != null) {
125
- Logger.debug("Location received: " + location.getLatitude() + ", " + location.getLongitude());
126
- }
127
120
  Intent intent = new Intent(ACTION_BROADCAST);
128
121
  intent.putExtra("location", location);
129
122
  intent.putExtra("id", id);
@@ -133,9 +126,8 @@ public class BackgroundGeolocationService extends Service {
133
126
  }
134
127
  @Override
135
128
  public void onLocationAvailability(LocationAvailability availability) {
136
- Logger.debug("Location availability: " + availability.isLocationAvailable());
137
129
  if (!availability.isLocationAvailable()) {
138
- Logger.debug("Location not available");
130
+ Logger.warn("Location not available - check if GPS is enabled");
139
131
  }
140
132
  }
141
133
  };
@@ -152,13 +144,11 @@ public class BackgroundGeolocationService extends Service {
152
144
  // permissions are not yet granted. Rather than check the permissions, which is fiddly,
153
145
  // we simply ignore the exception.
154
146
  try {
155
- Logger.debug("Requesting location updates with priority: " + priority + ", interval: " + interval);
156
147
  watcher.client.requestLocationUpdates(
157
148
  watcher.locationRequest,
158
149
  watcher.locationCallback,
159
150
  null
160
151
  );
161
- Logger.debug("Location updates requested successfully");
162
152
  } catch (SecurityException e) {
163
153
  Logger.error("SecurityException when requesting location updates", e);
164
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azatek/background-geolocation",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Capacitor plugin for background geolocation tracking with configurable GPS accuracy modes (HIGH/BALANCED/LOW/PASSIVE) for battery optimization. Fork of @capacitor-community/background-geolocation with enhanced accuracy control.",
5
5
  "keywords": [
6
6
  "capacitor",