Skip to content

Instantly share code, notes, and snippets.

@walteranyika
Created December 13, 2018 07:38
Show Gist options
  • Select an option

  • Save walteranyika/f8e354922561ddaaad0a7b98e5278c76 to your computer and use it in GitHub Desktop.

Select an option

Save walteranyika/f8e354922561ddaaad0a7b98e5278c76 to your computer and use it in GitHub Desktop.
Geoquery Mysql from a specific LatLng
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