5

I got this Example Map

SampleMap: http://techinfo.co.id/test/map.php

I make Boundary Polygon shape ,

-6.875165174925262, 107.56293296813965
-6.882663904407988, 107.66730308532715
-6.980818117491586, 107.67210960388184
-6.97093546084682, 107.54508018493652

And How to check if the given Lat, Lng is -6.935884,107.611592 in those Boundary Area

But what i need is without Google Maps Api .. because it's gonna be Offline

haidarvm
  • 171
  • 1
  • 1
  • 3

4 Answers4

2

a simple algorithm would consist in checking that you are on the "good" side of the lines that build your polygon. For instance, the long of your point has to be larger than the long of the West side and smaller than the long of your East side at the lat of your point.

e.g.

Long_point >  Long_LowerLeft + Lat_point * ( Long_UpperLeft - Long_LowerLeft)/ ( Lat_UpperLeft - Lat_LowerLeft)

for more complex shapes, you need to draw a line from your point (in any arbitrary direction) and you are inside if the number of intersection with the sides of your polygon is uneven.

radouxju
  • 49,636
  • 2
  • 71
  • 144
2

Although your question probably is harder than it seems due to curvature (spheical trig) issues, if you're happy to ignore that, there are a few ways to do a point-in-polygon check. I've used a ray casting algorithm, and you should be able to find example code somewhere to do that.

If you're using Python, just use Shapely. If Javascript, here's some code.

Alex Leith
  • 13,453
  • 30
  • 69
  • i did download Python Shapely but it failed to install ImportError: No module named setuptools.extension – haidarvm Mar 07 '14 at 08:45
  • Python is widely used, just google the error message: http://stackoverflow.com/questions/14426491/python-3-importerror-no-module-named-setuptools – Alex Leith Mar 10 '14 at 08:59
2

I found the correct answer here ...

it's tested many times and works like a charm

http://tutorialspots.com/php-detect-point-in-polygon-506.html

haidarvm
  • 171
  • 1
  • 1
  • 3
0

You can do this type of thing using GDAL/OGR library in python. Can also do it with the excellent jsts library https://github.com/bjornharrtell/jsts in javascript.

Lafleur
  • 131
  • 3