Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Find Point in polygon javascript

I found this solution in php : Find Point in polygon PHP

I change it in javascript

if (is_in_polygon(points_polygon, vertices_x, vertices_y, longitude_x, latitude_y)){
   console.log("Is in polygon");
}
else console.log("Is not  in polygon");

 function is_in_polygon(points_polygon, vertices_x, vertices_y, longitude_x, latitude_y) {
            i = j = c = 0;
            for (var i = 0, j = points_polygon - 1; i < points_polygon; j = i++) {
               if (((vertices_y[i] > latitude_y != (vertices_y[j] > latitude_y)) &&
                     (longitude_x < (vertices_x[j] - vertices_x[i]) * (latitude_y - vertices_y[i]) / (vertices_y[j] - vertices_y[i]) + vertices_x[i])))
                  c = !c;
            }
            return c;
         }

For test using this values :

var vertices_x = [37.628134, 37.629867, 37.62324, 37.622424]; 

 var vertices_y = [-77.458334,-77.449021,-77.445416,-77.457819];

 var points_polygon = vertices_x.length;

var longitude_x = 37.62850;
var latitude_y = -77.4499;

The function returned "Is in polygon"

Test 2 : I got points from drawing polygon leaflet map

var vertices_x = [49.209972,49.087808,48.231534,48.377689];

 var vertices_y = [1.658936, 3.131104, 3.35083, 1.647949];

 var points_polygon = vertices_x.length;

longitude_x = 2.3485;
latitude_y = 48.8537;

The point is inside polygon visually But the function returned "Is not in polygon"

I don't find what the problem .Any idea please for this problem

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda