react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Issue with Polygonal Geofencing on iOS
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.
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.
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]
]
});
Your Polygon shape is highly abnormal. Fix it.
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]
]
})
```
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
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.
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
Bad Polygon
It's like a pencil drawing a line to connect the vertices
in the order provided.
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.
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.
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.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.