10 Aug 2000 xach   » (Master)

Use PHP to write (My)SQL to discover distances:

function great_circle_mysql_formula($place1, $place2)
{
        $la0 = "((pi() / 2) - radians(90 - $place1[0]))";
        $la1 = "((pi() / 2) - radians(90 - $place2[0]))";
        $lo0 = "radians($place1[1])";
        $lo1 = "radians($place2[1])";

return "(6378 / 1.609344) * acos( cos($la0) * cos($la1) * cos($lo0 - $lo1) + sin($la0) * sin($la1) )"; }

You could pass in literal numbers for latitude and longitude in place1 and place2, or (more useful) column names, if you happen to have a table with some latitude and longitude data in it. The "(6378 / 1.609344)" is a constant that specifies the value is in miles; remove the "/ 1.609344" if you're into kilometers.

Shamelessly copied from Perl's Math::Trig module.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!