react-nativenpmgeofencing

React native GeoFencing geolib library


Hello there I'm using @mauron85/react-native-background-geolocation' to get my current coordinates and https://www.npmjs.com/package/geolib library to check if my location is inside a polygon my code is bellow

var tf = geolib.isPointInPolygon({ latitude: {lat: location.latitude}, longitude: {lng: location.longitude} }, [
    { latitude: 27.483871, longitude:  95.204824},
    { latitude: 27.484353, longitude: 95.195472},
    { latitude: 27.492926, longitude: 95.4932795 },
    { latitude: 27.492956, longitude: 95.177179 },

  ]);

however tf is always false even if its within the boundary But when I hard code my location (a location inside the boundary it is true) the code is bellow

var tf = geolib.isPointInPolygon({ latitude: 27.488464, longitude: 95.2020986 }, [
    { latitude: 27.483871, longitude:  95.204824},
    { latitude: 27.484353, longitude: 95.195472},
    { latitude: 27.492926, longitude: 95.4932795 },
    { latitude: 27.492956, longitude: 95.177179 },

  ]);

I have tried other library and failed can anyone help me fix this.


Solution

  • apparently this was caused by a null pointer. fixed it with an if else statement.