Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Incorrect Locations #2193

Open
shubhlumber opened this issue Oct 28, 2024 · 5 comments
Open

Getting Incorrect Locations #2193

shubhlumber opened this issue Oct 28, 2024 · 5 comments

Comments

@shubhlumber
Copy link

Your Environment

  • Plugin version:4.16.5
  • Platform: iOS or Android IOS
  • OS version: 17
  • Device manufacturer / model: Iphone
  • React Native version (react-native -v):0.73.6
  • Plugin config
useEffect(() => {
  if (Platform.OS !== 'web') {
    const onProvider: Subscription = BackgroundGeolocation.onProviderChange((event) => {
      switch (event.status) {
        case BackgroundGeolocation.AUTHORIZATION_STATUS_DENIED:
          break;
        case BackgroundGeolocation.AUTHORIZATION_STATUS_ALWAYS:
          break;
        case BackgroundGeolocation.AUTHORIZATION_STATUS_WHEN_IN_USE:
          break;
      }
    });

    const onLocation: Subscription = BackgroundGeolocation.onLocation(
      (location) => {
        setLongitude(location?.coords.longitude);
        setLatitude(location?.coords.latitude);
      },
      (error) => {
        console.log('[onLocation] ERROR: ', error);
      }
    );

    const http: Subscription = BackgroundGeolocation.onHttp((response) => {
      console.log('http', response);
    });

    const motionChange: Subscription = BackgroundGeolocation.onMotionChange((event) => {});
    /// 2. ready the plugin.
    BackgroundGeolocation.ready({
      notification: {
        priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_DEFAULT,
        title: 'abc',
        text: 'abc is tracking you',
      },
      isMoving: false,
      url: `abc`,
      autoSync: false,
      maxRecordsToPersist: 1,
      method: 'POST',
      elasticityMultiplier: 6,
      distanceFilter: 15,

      headers: {
        Authorization: 'Bearer ' + token.authToken,
        timezone: moment.tz.guess(),
      },
      showsBackgroundLocationIndicator: true,
      httpRootProperty: '.',
      locationTemplate:
        '{"latitude":<%= latitude %>,"longitude":<%= longitude %>,"time":"<%= timestamp %>"}',
      backgroundPermissionRationale: {
        title: 'Allow abc to use the location',
        message: 'abc.',
        positiveAction: 'Change to {backgroundPermissionOptionLabel}',
        negativeAction: 'Cancel',
      },
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      stopTimeout: 1,
      debug: false,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      stopOnTerminate: false,
      startOnBoot: true,
    })
      .then((state) => {})
      .catch((err) => console.error(err));

    return () => {
      onProvider.remove();
      onLocation.remove();
      http.remove();
      motionChange.remove();
    };
  }
}, []);

Expected Behavior

Getting Correct Locations Point

Actual Behavior

At 2024-10-18 06:56:26.885, the library generated this location: 📍<+40.94316423, -111.89047783> +/- 68.46m (speed -1.00 m/s, course -1.00) @ 10/18/24, 6:51:36 AM MDT

Then, at 2024-10-18 06:56:40.789, the library generated this location: 📍<+40.98457200, -111.89573687> +/- 4.58m (speed 0.00 m/s, course -1.00) @ 10/18/24, 6:56:40 AM MDT

These two points are about 3.3 miles apart, which seems impossible within this short time frame. Could you help us understand why such a large location shift is occurring?

Steps to Reproduce

Context

Debug logs

Logs
2024-10-18 06:56:23.269 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager stop] 
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:23.269 ℹ️-[TSLocationManager clearLastOdometerLocation] 

2024-10-18 06:56:23.269 🔴-[TSGeofenceManager stop] 

2024-10-18 06:56:23.269 🔴-[TSGeofenceManager stopMonitoringSignificantLocationChanges] 

2024-10-18 06:56:23.269 🔴-[TSGeofenceManager stopUpdatingLocation] 

2024-10-18 06:56:23.269 🔴-[TSGeofenceManager stopMonitoringGeofences] 

2024-10-18 06:56:23.271 🔴-[PolygonGeofencingService stop] 

2024-10-18 06:56:23.272 ℹ️-[PolygonGeofencingService persistMonitoredPolygons] {
}

2024-10-18 06:56:23.272 🔴-[TSLocationManager stopUpdatingLocation] 

2024-10-18 06:56:23.273 ℹ️-[TSDBLogger db_save] Log committed

2024-10-18 06:56:23.298 🔴-[TSLocationManager stopMonitoringBackgroundFetch] BackgroundFetch: OFF

2024-10-18 06:56:23.298 🔴-[TSLocationManager stopMonitoringSignificantLocationChanges] 

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager log:message:] [RNBackgroundGeolocation startObserving]

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] location

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] motionchange

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] activitychange

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] heartbeat

2024-10-18 06:56:23.298 ℹ️-[TSGeofenceManager onGeofence:] 

2024-10-18 06:56:23.298 ℹ️-[TSGeofenceManager onGeofencesChange:] 

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] http

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] providerchange

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] schedule

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] powersavechange

2024-10-18 06:56:23.298 ℹ️-[TSHttpService onConnectivityChange:] 

2024-10-18 06:56:23.298 ℹ️-[TSLocationManager on:success:failure:] enabledchange

2024-10-18 06:56:23.298 ℹ️-[TSHttpService onAuthorization:] 

2024-10-18 06:56:23.305 ℹ️-[TSConfig persist] 

2024-10-18 06:56:23.307 ℹ️-[TSConfig persist] 

2024-10-18 06:56:23.308 ℹ️-[TSConfig persist] 

2024-10-18 06:56:23.308 ℹ️-[TSConfig persist] 

2024-10-18 06:56:23.309 ✅-[LocationDAO unlock]_block_invoke UNLOCKED ALL RECORDS

2024-10-18 06:56:23.309 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1

2024-10-18 06:56:23.309 ℹ️-[TSConfig persist] 

2024-10-18 06:56:23.309 ℹ️-[TSConfig persist] 

2024-10-18 06:56:23.310 🔵-[TSLocationManager ready] 

2024-10-18 06:56:23.933 ℹ️-[TSLog destroy] SUCCESS

2024-10-18 06:56:26.864 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager start] 
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:26.864 ℹ️-[TSLocationManager doStart:] trackingMode: 1

2024-10-18 06:56:26.864 ℹ️-[TSConfig persist] 

2024-10-18 06:56:26.866 🎾-[TSGeofenceManager start] 

2024-10-18 06:56:26.867 🎾-[SOMotionDetector startDetection] 

2024-10-18 06:56:26.867 🔵-[TSLocationManager setPace:] 0

2024-10-18 06:56:26.871 🎾-[TSLocationManager startUpdatingLocation] Location-services: ON

2024-10-18 06:56:26.883 ✅-[SOMotionDetector startDetection]_block_invoke Enabled M7 MotionActivity updates

2024-10-18 06:56:26.883 ℹ️+[LocationAuthorization run:onCancel:] status: 3

2024-10-18 06:56:26.884 🎾-[TSLocationManager startMonitoringBackgroundFetch] BackgroundFetch: ON

2024-10-18 06:56:26.885 
📍<+40.94316423,-111.89047783> +/- 68.46m (speed -1.00 mps / course -1.00) @ 10/18/24, 6:51:36 AM Mountain Daylight Time

2024-10-18 06:56:26.885 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 290403 ms
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:26.885 ℹ️-[TSLocationManager locationManager:didUpdateLocations:] Received stale motionchange location.  Retrying...

2024-10-18 06:56:26.890 ℹ️-[TSLocationManager startMonitoringBackgroundFetch]_block_invoke Configured BackgroundFetch

2024-10-18 06:56:26.905 
📍<+40.98391033,-111.89461335> +/- 228.33m (speed -1.00 mps / course -1.00) @ 10/18/24, 6:56:26 AM Mountain Daylight Time

2024-10-18 06:56:26.905 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager locationManager:didUpdateLocations:] Enabled: 1 | isMoving: 0 | df: -1.0m | age: 8 ms
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:26.905 ✅-[TSLocationManager locationManager:didUpdateLocations:] Acquired motionchange position: <+40.94316423,-111.89047783> +/- 68.46m (speed -1.00 mps / course -1.00) @ 10/18/24, 6:51:36 AM Mountain Daylight Time

2024-10-18 06:56:26.905 🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 200

2024-10-18 06:56:26.906 🔴-[TSLocationManager stopUpdatingLocation] 

2024-10-18 06:56:26.906 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 68.5

2024-10-18 06:56:26.906 ℹ️-[PolygonGeofencingService setLocation:] Already updating location <IGNORED>

2024-10-18 06:56:26.906 🎾-[TSLocationManager startMonitoringSignificantLocationChanges] 

2024-10-18 06:56:26.908 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1

2024-10-18 06:56:26.908 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 43AA54CA-28C1-48C6-B764-1FDD8E8F8927

2024-10-18 06:56:26.925 ℹ️-[PolygonGeofencingService setLocation:] Already updating location <IGNORED>

2024-10-18 06:56:33.181 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:34.746 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:37.618 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:40.177 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:40.776 ⚠️-[TSLocationManager start] Already started (ignored)

2024-10-18 06:56:40.777 🔵-[TSLocationManager getCurrentPosition:] 

2024-10-18 06:56:40.777 🎾-[LocationManager startUpdatingLocation] ON



2024-10-18 06:56:40.779 ℹ️-[TSConfig persist] 

2024-10-18 06:56:40.783 ℹ️-[TSConfig persist] 

2024-10-18 06:56:40.784 ℹ️-[TSDBLogger db_save] Log committed

2024-10-18 06:56:40.785 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1

2024-10-18 06:56:40.785 ℹ️-[TSConfig persist] 

2024-10-18 06:56:40.789 ℹ️+[LocationAuthorization run:onCancel:] status: 3

2024-10-18 06:56:40.789 
📍<+40.98457200,-111.89573687> +/- 4.58m (speed 0.00 mps / course -1.00) @ 10/18/24, 6:56:40 AM Mountain Daylight Time

2024-10-18 06:56:40.789 🔴-[LocationManager stopUpdatingLocation] OFF

2024-10-18 06:56:40.789 
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 1 of 1 (589 ms old)
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:40.789 ℹ️-[PolygonGeofencingService setLocation:] Already updating location <IGNORED>

2024-10-18 06:56:40.789 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 36.5

2024-10-18 06:56:40.789 ℹ️-[TSConfig persist] 

2024-10-18 06:56:40.790 🔵-[TSConfig incrementOdometer:] 76497.0

2024-10-18 06:56:40.790 ℹ️-[PolygonGeofencingService setLocation:] Already updating location <IGNORED>

2024-10-18 06:56:40.797 ℹ️-[LocationDAO shrink:]_block_invoke maxRecordsToPersist: 1

2024-10-18 06:56:40.797 ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: 38C108E8-5BC5-4907-86B1-2F9D3DDD35B9

2024-10-18 06:56:40.814 
╔═══════════════════════════════════════════════════════════
║ -[TSHttpService flush:] 
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:40.815 ✅-[BackgroundTaskManager createBackgroundTask] 11

2024-10-18 06:56:40.816 ✅-[TSHttpService schedulePost] LOCKED: 38C108E8-5BC5-4907-86B1-2F9D3DDD35B9

2024-10-18 06:56:41.253 ℹ️-[TSLog destroy] SUCCESS

2024-10-18 06:56:41.965 🔵-[HttpResponse handleResponse] Response: 200

2024-10-18 06:56:41.972 ✅-[TSHttpService post:]_block_invoke DESTROY: 38C108E8-5BC5-4907-86B1-2F9D3DDD35B9

2024-10-18 06:56:41.972 
╔═══════════════════════════════════════════════════════════
║ -[TSHttpService finish:error:] Success: 1
╚═══════════════════════════════════════════════════════════

2024-10-18 06:56:41.972 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 11 OF (
    11
)

2024-10-18 06:56:43.087 🔵-[TSLocationManager onSuspend:] enabled? 1)

2024-10-18 06:56:43.092 ℹ️-[TSDBLogger db_save] Log committed

2024-10-18 06:56:43.110 ℹ️-[TSDBLogger db_save] Log committed

2024-10-18 06:56:43.110 ℹ️-[TSLocationManager removeListeners] 

2024-10-18 06:56:43.110 🔵-[TSLocationManager onAppTerminate] stopOnTerminate? 0

2024-10-18 06:56:43.110 🔵-[TSLocationManager startMonitoringStationaryRegion:radius:] Radius: 200

2024-10-18 07:01:21.475 ℹ️-[TSDBLogger db_delete] maxAge: 259200

2024-10-18 07:01:21.477 ℹ️-[TSLocationManager init] 
2024-10-18 07:01:21.478 ℹ️-[GeofenceDAO init] CREATE TABLE IF NOT EXISTS geofences (id INTEGER PRIMARY KEY AUTOINCREMENT, identifier TEXT NOT NULL UNIQUE, latitude DOUBLE NOT NULL, sin_latitude DOUBLE NOT NULL, cos_latitude DOUBLE NOT NULL, longitude DOUBLE NOT NULL, sin_longitude DOUBLE NOT NULL, cos_longitude DOUBLE NOT NULL, radius DOUBLE NOT NULL, notifyOnEntry BOOLEAN NOT NULL DEFAULT 0, notifyOnExit BOOLEAN NOT NULL DEFAULT 0, notifyOnDwell BOOLEAN NOT NULL DEFAULT 0, loiteringDelay DOUBLE NOT NULL DEFAULT 0, extras TEXT, vertices TEXT)

2024-10-18 07:01:21.478 ℹ️-[GeofenceDAO init] CREATE index IF NOT EXISTS identifier ON geofences (identifier);CREATE index IF NOT EXISTS latitude ON geofences (latitude);CREATE index IF NOT EXISTS longitude ON geofences (longitude);CREATE index IF NOT EXISTS sin_latitude ON geofences (sin_latitude);CREATE index IF NOT EXISTS cos_latitude ON geofences (cos_latitude);CREATE index IF NOT EXISTS sin_longitude ON geofences (sin_longitude);CREATE index IF NOT EXISTS cos_longitude ON geofences (cos_longitude);

2024-10-18 07:01:21.499 🔵-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 3

2024-10-18 07:01:21.503 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-10-18 07:01:21.503 🔵-[PolygonGeofencingService locationManager:didChangeAuthorizationStatus:] 3

2024-10-18 07:01:21.503 🔵-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 3

2024-10-18 07:01:21.503 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-10-18 07:01:21.503 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-10-18 07:01:21.503 ℹ️+[LocationAuthorization run:onCancel:] status: 3

2024-10-18 07:01:21.598 
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager stop] 
╚═══════════════════════════════════════════════════════════

@christocracy
Copy link
Member

The plug-in is only the mailman, delivering to you locations provided by the native location api.

One location has an accuracy of 68.46m (probably provided by wifi) while the other was 4.58m (probably from gps).

If you don’t like the location.coords.accuracy of some particular location, throw it away.

@shubhlumber
Copy link
Author

Since we are using the library's URL method, which automatically sends the coordinates to our API database, how can we filter out locations based on location.coords.accuracy for specific coordinates?

@christocracy
Copy link
Member

how can we filter out locations based on location.coords.accuracy for specific coordinates?

At your server, you should analyze incoming data and throw out undesirable locations.

@shubhlumber
Copy link
Author

Currently, we are sending the following locationTemplate to our database:

{"latitude":<%= latitude %>,"longitude":<%= longitude %>,"time":"<%= timestamp %>"}

This includes only latitude, longitude, and time. Is there a way to also fetch location.coords.accuracy so that we can save it in our database and use it for filtering?

@christocracy
Copy link
Member

See the API docs Config.locationTemplate to learn about how which attributes are available to you in your template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants