-1

I use Leaflet draw maps on the frontend to draw polygons.

After polygons are drawn, I have array with coordinates (latitude, longitude) of these polygons.

In the end, I need to check on the backend (in offline mode), if given point (latitude, longitude) belongs to some polygon.

I understand, that it should be possible. But earth is a sphere, polygon lies down on the ground surface, and I have no idea how to do this.

How is it possible to check that?

ProgramFOX
  • 6,131
  • 11
  • 45
  • 51
avasin
  • 9,186
  • 18
  • 80
  • 127

2 Answers2

0

Simplest solution would be to use Maps offering which has funcitonality in the polygon class to check whether the point is inside it.

And if your offering does not have it, then you would need to do the math parts yourself, here's few links to some help that should get you started:

  1. Point in polygon queries @ wikipedia
  2. Some Codes and explanations at GeeksforGeeks
  3. Older question on the topic here at SO
Community
  • 1
  • 1
Dr.Jukka
  • 2,346
  • 2
  • 15
  • 20
0

You can keep the angles between -180 and 180 then use a point in poly test:Easy way to keeping angles between -179 and 180 degrees.

Community
  • 1
  • 1
Micromega
  • 12,486
  • 7
  • 35
  • 72
  • I don't understand why, as my question, as all answers were downvoted. I can see no reason or no explanation, and this is big problem of this website. I upvoted all answers to fix that. Thanks for your response. – avasin Apr 25 '14 at 08:01
  • I think you need to keep angles between -180 and 180. I'm not sure why you upvote the other answerr and NOT ACCEPT MY ANSWER? I can write about poly in point test but there is already many Q&A. – Micromega Apr 25 '14 at 09:08
  • first of all, i think that it is correct answer too. from one side, i disagree with it's downvote. from another side - a man have spent some time for that, and i want to thank him. i have stupid mummy sons, that downvotes everything without explanation. secondly, i will choose and mark answer as correct when i will decide. thanks. – avasin Apr 25 '14 at 11:11
  • IMO then your question isn't clear. Can you elaborate when the angle is greater -180 an 180? – Micromega Apr 25 '14 at 11:36