transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.62k stars 428 forks source link

Issue with Polygonal Geofencing on iOS #1846

Closed aanjan123 closed 3 months ago

aanjan123 commented 11 months ago

Your Environment

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.
christocracy commented 11 months ago

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
aanjan123 commented 11 months ago

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]
  ]
});
christocracy commented 11 months ago

Your Polygon shape is highly abnormal. Fix it.

aanjan123 commented 11 months ago

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]
      ]
    })
yonkahlon commented 11 months ago

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

christocracy commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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

SrikanthEnuguru commented 11 months ago

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.

christocracy commented 11 months ago

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 commented 11 months ago

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.

github-actions[bot] commented 4 months ago

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

github-actions[bot] commented 3 months ago

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