Skip to content

Instantly share code, notes, and snippets.

@nicolasiensen
Created August 9, 2013 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolasiensen/6196787 to your computer and use it in GitHub Desktop.
Save nicolasiensen/6196787 to your computer and use it in GitHub Desktop.
Distance between two geospatial points in MySql
SET @orig_lat = "50";
SET @orig_lng = "5";
SET @dest_lat = "45";
SET @dest_lng = "30";
SELECT 3956 * 2 * ASIN(SQRT( POWER(SIN((@orig_lat - @dest_lat) * pi()/180 / 2), 2) + COS(@orig_lat * pi()/180) * COS(@dest_lat * pi()/180) * POWER(SIN((@orig_lng - @dest_lng) * pi()/180 / 2), 2) ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment