I have function that takes a users coordinates and tests it against a polygon. When I create the fence with whole numbers such as [3,2], [3,4],[5,6],[3,2]. My function returns correctly. I tried inputting real data to create a geofence and used the chrome devtools to simulate a custom geolocation that was within the geofence. However, with real coordinates ( 40.225928, -111.660785) it does not return that the point is within the polygon. Below is my object and method.
const fence = {Fence1: turf.polygon([
[[40.225,-111.658], [40.2229,-111.664],
[40.223,-111.667], [40.225,-111.668],
[ 40.226,-111.666], [40.225,-111.658]]
])
};
module.exports = {
check_fences: (req,res,next) => {
var pt1 = turf.point([req.body.latitude, req.body.longitude]);
for (key in fences) {
if(turf.intersect(pt1, fences[key])) {
console.log(key)
fence = key
}
}
if(resort) {
return res.status(200).send(resort)
} else {
return res.status(200).send('NOT IN FENCE')
}
The req body object is coming in as: { latitude: 40.224411, longitude: -111.66478 }
Developing with ReactJS
I am at a loss for why this is not working.