Skip to content

Instantly share code, notes, and snippets.

@jbouzekri
jbouzekri / get_distance_meters
Last active Aug 29, 2015
get_distance_meters function : get distance in MySQL
View get_distance_meters
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