[snip] we are working on a small project which needs to calculate the closest distances from an address and/or zipcode entered into a search box. It will read from a MySQL database of companies, which store their address and zipcodes.
looking for the best way to approach this. I've seen some zipcode Perl modules on Cpan, but nothing for helping calculation distances. Can someone point me in the right direction to accomplish this ... thx's :) [/snip] We have started storing latitude and longitude coordinates on our databases which lends itself to distance calculations. For example, here is a PHP function which performs the distance calculation function distance($lat1, $lon1, $lat2, $lon2) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; return $miles; } You may be able to do it entirely in a query by utilizing MySQL's math functions; http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html HTH -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]