Created
December 5, 2013 15:20
-
-
Save DeviaVir/7807308 to your computer and use it in GitHub Desktop.
Calculating distance between two points (Latitude, Longitude).
Author: https://coderwall.com/st0ik
This file contains hidden or 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
$lat = 41.118491 // Users latitude | |
$lng = 25.404509 // Users longitude | |
SELECT *, | |
( 6371 * acos( cos( radians($lat) ) | |
* cos( radians( latitude ) ) | |
* cos( radians( longitude ) - radians($lng) ) + sin( radians($lat) ) | |
* sin( radians( latitude ) ) ) ) | |
AS calculated_distance | |
FROM settings as T | |
HAVING calculated_distance <= (SELECT distance FROM settings WHERE sid=T.sid) | |
ORDER BY distance_calc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment