Geofence. Check if a point is inside a polygon. JavaScript. Map

3.- Map. Check if a point is inside a polygon on a map. Geofence.

p251_geofenceJavaScript_Mapa.aia (4.4 KB)

  • We draw a polygon in a Map using LineString.PointsFromString, note that the initial and final coordinates are the same so that the polygon closes:

LineString.PointsFromString=[[36.50318,-6.27281],[36.50226,-6.27231],[36.50198,-6.27311],[36.50291,-6.27361],[36.50263,-6.27298],[36.50318,-6.27281]]

  • We set the check polygon with these coordinates:

poligono = [[36.50318,-6.27281],[36.50226,-6.27231],[36.50198,-6.27311],[36.50291,-6.27361],[36.50263,-6.27298]]

  • We move by means of a Clock, a point horizontally:

punto = [36.5027,h]

  • We can stop the Clock using "Stop" and tap on the map, using the TapAtPoint block we can see if the point is inside or outside the polygon.

- Designer.

- Blocks.

- Comments.

  • It also works if we set the query polygon by repeating the initial coordinate at the end:
    poligono = [[36.50318,-6.27281],[36.50226,-6.27231],[36.50198,-6.27311],[36.50291,-6.27361],[36.50263,-6.27298],[36.50318,-6.27281]]

  • The code returns a String "true" or "false".