Skip to content

Instantly share code, notes, and snippets.

@jbouzekri
jbouzekri / get_distance_meters
Last active August 29, 2015 14:01
get_distance_meters function : get distance in MySQL
DELIMITER //
/*
Exemple :
You have table city with latitude and longitude column.
get_distance_meters(my_latitude, my_longitude, city.latitude, city.longitude)
return the distance in km
*/
CREATE FUNCTION get_distance_meters ( lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT ) RETURNS DOUBLE PRECISION
BEGIN