MySQL计算两个坐标点的距离

-- 定义计算距离的函数
delimiter $
drop function if exists earth_distance$
create function earth_distance ( latitude1 float, longitude1 float, latitude2 float, longitude2 float )
returns float
begin
  set @radius = 6371000;
 set @rad = pi()/180.0;
 set @lat1 = latitude1 * @rad;
 set @lng1 = longitude1 * @rad;
 set @lat2 = latitude2 * @rad;
 set @lng2 = longitude2 * @rad;
 set @theta = @lng2 - @lng1;
 set @dist = acos(sin(@lat1) * sin(@lat2) + cos(@lat1) * cos(@lat2) * cos(@theta));
 return @dist * @radius;
end$

 

参阅资料 https://www.cnblogs.com/qdhxhz/p/10825538.html

转载于:https://my.oschina.net/u/3625745/blog/3072285

你可能感兴趣的:(数据库)