react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Issue with Polygonal Geofencing on iOS

Open aanjan123 opened this issue 1 year ago • 12 comments

Your Environment

  • Plugin version: 4.14.2
  • Platform: iOS
  • OS version: 17.0.1
  • Device manufacturer / model: iPhone 12 & Also tested in simulator with manually updating location
  • React Native version (0.67.4):
  • Plugin config

  BackgroundGeolocation.onGeofence(geofence => {
      console.log("[geofence] ", { geofence });
    })

BackgroundGeolocation.addGeofence({
      identifier: 'Home',
      notifyOnEntry: true,
      notifyOnExit: true,
      vertices: [
        [27.672427, 85.345839],
        [27.672424, 85.345855],
        [27.672439, 85.345825],
        [27.672446, 85.345845],
        [27.672411, 85.345822],
        [27.672483, 85.345762],
        [27.672520, 85.345708]
      ]
    }).then(()=>{    
              BackgroundGeolocation.startGeofences();
});

    

Expected Behavior

I expected to receive callbacks upon entering and exiting a polygonal geofence region on the iOS platform, similar to the behavior I observed with circular geofencing.

Actual Behavior

However, when I transitioned to implementing polygonal geofencing, I did not receive any callbacks upon entering or exiting the region, despite following the example in the documentation.

I also have a question regarding the need to purchase a specific feature for iOS. Do we require a purchase for iOS as well? Will this feature not work in a debug build without purchasing it? It's important to note that I am currently only testing this on the iOS platform.

aanjan123 avatar Oct 10 '23 16:10 aanjan123

When I plot your vertices on a map, this is what your polygon looks like. Order of vertices matters.

Make a better polygon. Start with a simple square.

Screenshot 2023-10-10 at 12 49 12 PM

christocracy avatar Oct 10 '23 16:10 christocracy

ah Okay, but when I try to use the example values in the simulator updating location lat long manually, I was receiving callback in the case of circular geofencing but not in the case of polygonal geofencing.


BackgroundGeolocation.addGeofence({
  identifier: 'Home',
  notifyOnEntry: true,
  notifyOnExit: true,
  vertices: [
    [45.518947279987714, -73.6049889209514],  // <-- [lat, lng]
    [45.5182711292279, -73.60338649600598],
    [45.517082240237634, -73.60432670908212],
    [45.51774871402813, -73.60604928622278]
  ]
});

aanjan123 avatar Oct 10 '23 17:10 aanjan123

Your Polygon shape is highly abnormal. Fix it.

christocracy avatar Oct 10 '23 17:10 christocracy

updated my polygon geofencing vertices, still not receiving any callbacks

current verticies is given below

    BackgroundGeolocation.addGeofence({
      identifier: 'Home',
      notifyOnEntry: true,
      notifyOnExit: true,
      vertices: [
        [27.67254431189224, 85.34567377546588],
        [27.67265580548456, 85.34571645120293],
        [27.672523525017997, 85.3459234291403],
        [27.672426204385992, 85.34583167609148]
      ]
    })
    
    ```

aanjan123 avatar Oct 11 '23 08:10 aanjan123

Hi @aanjan123

If you close the polygon, i.e. copy coord 1 to the end like so:

BackgroundGeolocation.addGeofence({
      identifier: 'Home',
      notifyOnEntry: true,
      notifyOnExit: true,
      vertices: [
        [27.67254431189224, 85.34567377546588],
        [27.67265580548456, 85.34571645120293],
        [27.672523525017997, 85.3459234291403],
        [27.672426204385992, 85.34583167609148].
        [27.67254431189224, 85.34567377546588]
      ]
    })

It may work.

On Android, if I test with an open polygon (like your example) I don't get any events. When I closed the polygon I get ENTER events. Maybe this will work for you on iOS as well.

I'm not getting EXIT events though, and I'm not sure why yet. I have set "notifyOnExit: true," so still figuring it out

yonkahlon avatar Oct 12 '23 06:10 yonkahlon

You don't need to "close" a polygon by duplicating vertices.

The plug-in prints valuable logs to its log database when it evaluates polygons. You should be observing your logs.

christocracy avatar Oct 12 '23 10:10 christocracy

The Order of vertices matters and polygons are automatically "closed". I suggest you experiment using the Demo App, which includes a polygon geofence designer.

Good Polygon

IMG_0021

Bad Polygon

IMG_0022

christocracy avatar Oct 12 '23 14:10 christocracy

It's like a pencil drawing a line to connect the vertices in the order provided.

Here is a video of creating a polygon in the Demo app

christocracy avatar Oct 12 '23 14:10 christocracy

For circular geofencing, minimum reliable radius is 200m to receive entry and exit events.

Are there any such limitations for polygon geofencing too?

Since a polygon will be converted to a minimum enclosing circle, is 200m radius limitation applies to polygon geofencing too?

We observed that listeners are not being triggered for small polygons. When we increased the size of the polygon, geofencing worked as expected.

SrikanthEnuguru avatar Oct 13 '23 01:10 SrikanthEnuguru

Polygons depend upon the accuracy of the location and will work best outdoors where location accuracy is typically ~5m.

Indoor location accuracy is typically ~40m.

Don't test polygons while sitting indoors. Go outside to test them.

christocracy avatar Oct 13 '23 01:10 christocracy

for small polygons.

A small polygon to me is like a square or triangle having sides of 50m. I don't know what your idea of small is.

christocracy avatar Oct 13 '23 01:10 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 03 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 18 '24 01:05 github-actions[bot]