Calculating distance in Kilometres and Miles from Latitude and Longitude
I have seen many different ways of doing this, but to my knowledge this is the most accurate way. Using SQL you can have your database return the distance between 2 sets of Lat and Long points, and using some math functions also take into account the curvature of the earth.
Admittedly if you are calculating distances between 2 postcodes in the same state, within 500 miles or so of each other, the curve of the earth has practically no effect. However the distance between Sydney and San Francisco is significantly different when the world isn’t flat!
In this SQL the originating points are inserted (#longitude#, #latitude#), and it finds the distance to the postcode from the postcode table. This is the query we are using against the data I posted in my Geocoding Australia post.
This works in mySQL and SQL Server. If you need a distance in miles, simply remove the *8/5.