Reputation: 41
having a location coordinate(latitude,longitude), is it possible to check if it belongs to an area that have an array of coordinates (example when you draw a polygon on map that have array of coordinates) ? I am using JS, html5, and php and i would be flexible to solutions from other programming languages. Thank You a bunch in advance !
Upvotes: 2
Views: 2034
Reputation: 57683
One way could be a ray casting algorithm. The theory is to draw a virtual horizontally ray from outside the polygon to your point of interest and count how often it crosses any side of the polygon. If the number is even, your point is outside if it's odd it's inside the polygon.
Look here http://alienryderflex.com/polygon/ for more information and C code sample.
Upvotes: 5