I have an API that returns an array of latitudes and longitudes that define the boundaries of an area on a map(polygon).
In my react-native app, I have react-native-maps installed. How do I check if the user's location is in the polygon returned by the api?
I know this can be achieved with google maps web with the containsLocation()
function. Does a function like that exist for react-native-maps
?
The amount of east-to-west distance (measured in degrees) to display for the map region.
For anyone still looking for an easier alternative (or for Circle
support just like I needed it), look into using geolib
: https://github.com/manuelbieh/Geolib.
Installation is simple and straightforward:
$yarn add geolib
Afterward in your React Native project, import it using:
import geolib from 'geolib'
And then just use the API as explained in the README.md.
react-native-maps
doesn't expose that function, but there are two packages that I'm aware of that can help you:
react-native-geo-fencing that does the same as the google maps utility you've mentioned.
react-native-geo-fence handles location checks for you and exposes events you can hook into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With