module Geocoder::Sql

def full_distance(latitude, longitude, lat_attr, lon_attr, options = {})


http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
Based on the excellent tutorial at:

ATAN2(), DEGREES(), and RADIANS().
SQRT(), PI(), and trigonometric functions SIN(), COS(), ASIN(),
Distance calculation for use with a database that supports POWER(),
#
def full_distance(latitude, longitude, lat_attr, lon_attr, options = {})
  units = options[:units] || Geocoder.config.units
  earth = Geocoder::Calculations.earth_radius(units)
  "#{earth} * 2 * ASIN(SQRT(" +
    "POWER(SIN((#{latitude.to_f} - #{lat_attr}) * PI() / 180 / 2), 2) + " +
    "COS(#{latitude.to_f} * PI() / 180) * COS(#{lat_attr} * PI() / 180) * " +
    "POWER(SIN((#{longitude.to_f} - #{lon_attr}) * PI() / 180 / 2), 2)" +
  "))"
end