2

Is it possible to check if a location(Latitude, Longitude) is within a polygon using JAVA. I know this is possible in JavaScript. I found the Client library for Java but cant find ways to do this like ine JavaScript using e.g

containsLocation();

or if it is a way to use a url and do a http request with the url where i plot in the polygon and match it with the coordinates I want to check?

Ive tried the Client libs for Java but cant find any ways of doing it.

Any help is greatly appreciated.

PS: I must use Java

EDIT:

I found out this:

Polygon poly = new Polygon();

    poly.addPoint(100, 100);
    poly.addPoint(100, 0);
    poly.addPoint(0, 0);
    poly.addPoint(0, 100);

    Point p = new Point(99, 99);

    System.out.println(poly.contains(p));
wandapong
  • 59
  • 5
  • 1
    What did you try? Here's some math for you: http://math.stackexchange.com/questions/190111/how-to-check-if-a-point-is-inside-a-rectangle But note that the "map" is as earth so not flat –  Sep 15 '16 at 16:31
  • See also http://stackoverflow.com/questions/13772690/how-determine-if-point-is-within-rectangle-given-all-latitude-longitude-coordina –  Sep 15 '16 at 16:33
  • By trying i meant browse the library. I was more wondering if it's possible using the API. With a URL call or in the client lib. I will check out ur links. Thanks – wandapong Sep 15 '16 at 16:37
  • I edited the OP with what I want. The problem is it dosent accept double. I assume the concept would be the same to fill in the coordinates from the latitude and longitude and check wether x,y is inside the rectangle? – wandapong Sep 15 '16 at 19:56
  • I found out. You can use Path2d.Double() and it seems t work when i take 4 points in google maps and that would form a rectangle. – wandapong Sep 15 '16 at 20:30

0 Answers0