Created
June 8, 2012 08:09
-
-
Save niklasvincent/2894406 to your computer and use it in GitHub Desktop.
Geo comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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