google-mapsreact-nativepolygonreact-native-maps

Check if point exists within a polygon in react-native-maps?


I have an API that returns an array of latitudes and longitudes that define the boundaries of an area on a map(polygon).

an example of a 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?


Solution

  • react-native-maps doesn't expose that function, but there are two packages that I'm aware of that can help you:

    1. react-native-geo-fencing that does the same as the google maps utility you've mentioned.

    2. react-native-geo-fence handles location checks for you and exposes events you can hook into.