Searching geocoded information by distance
algorithm, geocoding, search
Solution
There are Spatial extensions available for MySQL 5 - an entry page to the documentation is here:
http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html
There are lots of details of how to accomplish what you are asking, depending upon how your spatial data is represented in the DB.
Another option is to make a function for calculating the distance using the Haversine formula mentioned already. The math behind it can be found here:
www.movable-type.co.uk/scripts/latlong.html
Hopefully this helps.
Problem
I have a database of addresses, all geocoded. What is the best way to find all addresses in our database within a certain radius of a given lat, lng? In other words a user enters (lat, lng) of a location and we return all records from our database that are within 10, 20, 50 ... etc. miles of the given location. It doesn't have to be very precise. I'm using MySQL DB as the back end.