# Fast(est) way to detect if point is in range of another point? (Geographic Coordinates)

I'm looking for a way to detect if 2 points are "near enough" each other for a match, and hopefully, if the range could be specified in metric system (each item may have different ranges, but there would be no change once it has been inserted).

I have already used Distance before for things like this, though the amount of data was significantly less, now I'm afraid it would be too slow for what I need.

Using simple logic, I thought about the fastest way to calculate that would be to do half the calculation already on the table, since one of the points has a constant range and location (neither can be changed later, worst case scenario, range can be changed, but then only need to update circle area), I could instead save it as a Circle format.

I'm not really sure, But as I looked more on it I reached a conclusion that usual GIS functions use the Cartesian Coordinate System for its calculations, which could work fine under a certain limited area, but because I would be working with GPS coordinates, I'm afraid that the farther away from points 0°,0°, the bigger the error margin may be too big (The radius could be from a few meters to a few Kms) and but I'm not sure if there are functions for Geographic Coordinates, or if anyone knows a way to draw a "deformed circle" accordingly based on the base latitude point.

• What software are you using or is this a coded solution (in which case, which language)? The answer will depend on it. Commented Sep 1, 2017 at 12:54
• I want to put this directly into the database, it has not been decided yet, I was considering PostgreSQL, but if a NoSQL DB does it better, I could try to implement it there too. Commented Sep 1, 2017 at 12:56
• I would think PostgreSQL/PostGIS extension would work. Enable PostGIS extension on your database, add geometry column to table, write query that buffers two records, and checks to see if their buffers intersect or not. Commented Sep 1, 2017 at 13:00