Search code examples
phpmongodbgeolocationgeospatialgeo

Calculate a boundary from set of geo locations


I have list of latitudes and longitudes.

These are acquired from reverse zip look up database and it's under a specific city (Dayton, OH).

39.721286   -84.133892
39.760000   -84.195900
39.757800   -84.177700
39.845339   -84.123287
...

I have a property database in mongodb and, each property has the location defined (lat/lng), when user enters "Dayton, OH", I'm grabbing Dayton's all the zip codes with relevant geo coordinates and what I want to do is to create a boundary and add 5 miles to it and search the property database which covers the lat/lng of dayton zip codes.

What's the best way to create a boundary (square/circle) to search a database within the range using this list of cordinates?


Solution

  • Found the solution, apparently the best approach is to calculate the border from application end using "convex hull" algorithm and then query.