Created
December 13, 2018 07:38
-
-
Save walteranyika/f8e354922561ddaaad0a7b98e5278c76 to your computer and use it in GitHub Desktop.
Geoquery Mysql from a specific LatLng
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
| SET @lat = 34.010396 ; | |
| SET @lng = -118.496029 ; | |
| SELECT m.school_id | |
| , m.location_id | |
| , m.school_name | |
| , m.lat | |
| , m.lng | |
| , ( ACOS( COS( RADIANS( @lat ) ) | |
| * COS( RADIANS( m.lat ) ) | |
| * COS( RADIANS( m.lng ) - RADIANS( @lng ) ) | |
| + SIN( RADIANS( @lat ) ) | |
| * SIN( RADIANS( m.lat ) ) | |
| ) | |
| * 6371 | |
| ) AS distance_in_km | |
| FROM mytable m | |
| ORDER BY distance_in_km ASC | |
| LIMIT 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment