Skip to content

Instantly share code, notes, and snippets.

@ichadhr
Last active October 7, 2019 15:36
Show Gist options
  • Save ichadhr/f5777e7c1cc9901e9ee0babc19960d9e to your computer and use it in GitHub Desktop.
Save ichadhr/f5777e7c1cc9901e9ee0babc19960d9e to your computer and use it in GitHub Desktop.
Geo latitude longtitude order

simple ordering lat long MySQL

SELECT
	*,
	6371 * ASIN(
		SQRT(
			POWER( SIN( ( '-8.637420' - sample.lat ) * pi( ) / 180 / 2 ), 2 ) + COS( '-8.637420' * pi( ) / 180 ) * COS( sample.lat * pi( ) / 180 ) * POWER( SIN( ( '115.253001' - sample.lng ) * pi( ) / 180 / 2 ), 2 ) 
		) 
	) AS distance 
FROM
	sample 
ORDER BY
	distance ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment