0
votes

I need some help, I've never done my own SQL search before and I'm trying to do this:

I have a database of names and locations (the locations are listed with a Latitude record and a Longitude record). Then, a user can search by entering their zip code (which is converted to longitude and latitude) and a distance they're willing to travel (in miles, which I can convert to lon/lat distance).

How can I return the results ordered by the distance away from their ZipCode?

Please keep in mind, I haven't ever done anything like this before.

1

1 Answers

1
votes

There's a mathematical formula for figuring the shortest distance between two points on a sphere. The formula and a JS implementation of it are here:

http://www.movable-type.co.uk/scripts/latlong.html

A T-SQL implementation is here:

http://weblogs.asp.net/jimjackson/archive/2009/02/13/calculating-distances-between-latitude-and-longitude-t-sql-haversine.aspx