Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 660
digiwebguy Avatar asked Feb 03 '18 06:02

digiwebguy


People also ask

What is Latitude Delta in react native maps?

The amount of east-to-west distance (measured in degrees) to display for the map region.


2 Answers

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.

like image 71
ItWillDo Avatar answered Sep 28 '22 03:09

ItWillDo


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.

like image 43
Marek Lisik Avatar answered Sep 28 '22 01:09

Marek Lisik