Skip to content

Instantly share code, notes, and snippets.

@niklasvincent
Created June 8, 2012 08:09
Show Gist options
  • Save niklasvincent/2894406 to your computer and use it in GitHub Desktop.
Save niklasvincent/2894406 to your computer and use it in GitHub Desktop.
Geo comparison
// MySQL
$sql = "SELECT all, the fields, you, want, ((ACOS(SIN(c.Latitude * PI() / 180) * SIN(" . $lat . " * PI() / 180) + COS(c.Latitude * PI() / 180) * COS(" . $lat . " * PI() / 180) * COS((c.Longitude - " . $lng . ") * PI() / 180)) * 180 / PI()) * 60 * 2) as distance FROM places ORDER BY distance DESC;";
// MongoDB
$this->places->find(array( 'loc' => array( '$near' => array($lat, $lng) ) ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment