# Formula to Check Latitude & Longitude is within Area without Google Maps Api

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

• Do you want to do this in python or javascript? Mar 6, 2014 at 10:42
• its ok i can do in python or javascript Mar 7, 2014 at 7:57
• numerous examples: gis.stackexchange.com/questions/208546/… Jan 22, 2018 at 23:33

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.

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.

• i did download Python Shapely but it failed to install ImportError: No module named setuptools.extension Mar 7, 2014 at 8:45
• Python is widely used, just google the error message: stackoverflow.com/questions/14426491/… Mar 10, 2014 at 8:59

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

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.