title: Java - How to check if a lat/lng coords are inside a polygon
body: <p>I want to check if a given point on a map (with its latitude and longitude) is inside a certain polygon. I have the vertex coords (in lat/long) of the polygon.</p>
  
  <p>I thought of creating a Polygon and check if point is inside, but it gives me that the point is always outside... Maybe the polygon does not work with georeferential coords?</p>
  
  <pre><code>Double[] xCoords = {40.842226, 40.829498, 40.833394, 40.84768, 40.858716}
  Double[] yCoords = {14.211753, 14.229262, 14.26617, 14.278701,  14.27715}
  Double[] myPoint = {40.86141, 14.279932};
  
  
  Path2D myPolygon = new Path2D.Double();
              myPolygon.moveTo(xCoords[0], yCoords[0]); //first point
              for(int i = 1; i &lt; xCoords.length; i ++) {
                  myPolygon.lineTo(xCoords[i], yCoords[i]); //draw lines
              }
              myPolygon.closePath(); //draw last line
  
                 if(myPolygon.contains(myPoint{0}, myPoint{1})) {
                  //it's inside;
  }
  </code></pre>
  
  <p>This is how it looks like in google maps</p>
  
  <p><a href="https://i.stack.imgur.com/xcAq3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xcAq3.jpg" alt="enter image description here"></a></p>
  
  <p>It always return false... but the point it's inside the polygon...</p>