Skip to content

Instantly share code, notes, and snippets.

@ruthlessfish
Created August 24, 2011 21:06
Show Gist options
  • Save ruthlessfish/1169240 to your computer and use it in GitHub Desktop.
Save ruthlessfish/1169240 to your computer and use it in GitHub Desktop.
haversine formula for MySQL in PHP
<?php
function haversine($lat1, $long1, $lat2, $long2)
{
return "(3959 * acos(cos(radians($lat1)) * cos(radians($lat2)) * cos(radians($long2) - radians($long1)) + sin(radians($lat1)) * sin(radians($lat2))))";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment