Let's say I have a huge list of latitude/longitude pairs, and I want to find all of the pairs within (say) a 500 mile radius of a user-input lat/lon, sorted in order of distance from the specified point.
First I calculate the points 500 miles N, S, E, and W, to specify a latitude/longitude grid rectangle that quickly pre-filters the records. Next I perform a (slower) Great Circle calculation for the remaining rows. Toss anything over 500 miles, and the rest of the distance values are saved in an array. Sort the array, all done. The closest point to the specified location is first, and so on.
I'm curious how that might be implemented in a SQL database, either local or (especially) online. Nested statements? Calculated fields? Would something other than the DBMS itself (php, VBA, etc.) do the calculating?
The most common online answer is "use the Google Maps API" but I want to know how it works under the hood.
First I calculate the points 500 miles N, S, E, and W, to specify a latitude/longitude grid rectangle that quickly pre-filters the records. Next I perform a (slower) Great Circle calculation for the remaining rows. Toss anything over 500 miles, and the rest of the distance values are saved in an array. Sort the array, all done. The closest point to the specified location is first, and so on.
I'm curious how that might be implemented in a SQL database, either local or (especially) online. Nested statements? Calculated fields? Would something other than the DBMS itself (php, VBA, etc.) do the calculating?
The most common online answer is "use the Google Maps API" but I want to know how it works under the hood.
Comment