Reputation: 391
I want to, given a latitude and longitude for a point, and a specific radius around that point in kilometers, calculate the maximum and minimum values for both latitude and longitude.
From the research I did, it seems that if you want to be precise, you should keep the approximation to the poles and equator in mind. So if possible, I'd prefer to know more about the precise version of the calculation, unless it's too complicated.
Upvotes: 1
Views: 3621
Reputation: 1010
It seems to me the answers must be due North, South, East, and West of the starting point. That makes calculating the max and min latitudes trivial given the radius of the earth. For longitude, you can calculate the radius of the earth at the given latitude and use that to calculate the max and min longitude. Am I missing a problem here?
Upvotes: 0
Reputation: 82934
It looks like you want code for a "bounding box". This allows you to do a "store locator" operation that doesn't calculate a distance for each store in the database. Step 0 (optional) is to build an index (on lat, lon) in your database. Step 1 is to calculate the box which is (lo_lat, hi_lat, lo_lon, hi_lon) and use it in a query which filters out unwanted rows. Step 2 calculates the distance of the remaining rows and and removes those which are outside the required circle.
This will help you with the details: http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates
Upvotes: 2