Return to Snippet

Revision: 21011
at December 1, 2009 20:22 by zingo


Initial Code
SELECT postcode, (3959*acos((sin(#latitude#/57.3) * sin(latitude/57.3))+ (cos(#latitude#/57.3) * cos(latitude/57.3) * cos((#longitude# - longitude)/57.3))))*8/5 AS exactDistance

FROM postcode

WHERE 1=1

ORDER BY (3959*acos((sin(#latitude#/57.3) * sin(latitude/57.3))+ (cos(#latitude#/57.3) * cos(latitude/57.3) * cos((#longitude# - longitude)/57.3))))*8/5

Initial URL
http://www.sixfive.co.uk/index.cfm/2007/4/9/Calculating-distance-in-Kilometres-and-Miles-from-Latitude-and-Longitude

Initial Description
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.

Initial Title
Calculating distance in Kilometres and Miles from Latitude and Longitude

Initial Tags
mysql, sql, math

Initial Language
SQL