For anyone interested, here's the MySQL function I've been using for
some time now to calculate distances in km:

create function distance(lat1 real, lng1 real, lat2 real, lng2 real)
returns real no sql
return ATAN2(SQRT(POW(COS(RADIANS(lat2)) * SIN(RADIANS(lng1 - lng2)), 2) +
                        POW(COS(RADIANS(lat1)) * SIN(RADIANS(lat2)) -
SIN(RADIANS(lat1)) *
                        COS(RADIANS(lat2)) *  COS(RADIANS(lng1 - lng2)), 2)),
                        (SIN(RADIANS(lat1)) * SIN(RADIANS(lat2)) +
COS(RADIANS(lat1)) *
                        COS(RADIANS(lat2)) * COS(RADIANS(lng1 -
lng2)))) * 6372.795;

Ugly, but it works.

Tobias Cohen
http://tobiascohen.com/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to rails-ocea...@googlegroups.com.
To unsubscribe from this group, send email to 
rails-oceania+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to