Created
April 26, 2012 11:19
-
-
Save revolunet/2498903 to your computer and use it in GitHub Desktop.
sql based geolocation query
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
# | |
# geolocate points 50km around a defined latitude/longitude | |
# | |
$latitude = 42.45679; | |
$longitude = 8.345678; | |
$sql = "SELECT ID, 3956 * 2 * ASIN(SQRT(POWER(SIN((" . $latitude . " - LAT) * 0.0174532925 / 2), 2) + "; | |
$sql .= "COS(" . $latitude . " * 0.0174532925) * COS(LAT * 0.0174532925) * POWER(SIN((" . $longitude . " - LON) * 0.0174532925 / 2), 2) "; | |
$sql .= ")) as DISTANCE from houses having DISTANCE < 50 ORDER BY DISTANCE ASC "; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see also : http://www.movable-type.co.uk/scripts/latlong-db.html