gpt4 book ai didi

mysql - 获取地球上两个坐标之间的距离

转载 作者:行者123 更新时间:2023-11-29 11:57:47 25 4
gpt4 key购买 nike

我尝试使用 here 中的公式获取两个坐标之间的距离

坐标为 1.5378236000、110.3372347000 和 1.5395056000、110.3373156000。

不知怎的,结果却大不相同。我相信“dist1”在 KM 中,但不确定“dist2”。

select 6371 * acos( cos( radians(1.5378236000) ) * cos( radians( 1.5395056000 ) ) * 
cos( radians( 1.5378236000 ) - radians(110.3373156000) )
+ sin( radians(1.5378236000) ) * sin( radians( 1.5395056000 ) ) ) AS dis1,
GetDistance(1.5378236000, 110.3372347000, 1.5395056000, 110.3373156000) as dis2

结果距离1:12091.536526805385
距离2:0.11190

获取距离函数

CREATE DEFINER=`root`@`localhost` FUNCTION `GetDistance`(
lat1 numeric (9,6),
lon1 numeric (9,6),
lat2 numeric (9,6),
lon2 numeric (9,6)
) RETURNS decimal(10,5)
READS SQL DATA
BEGIN
/* http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe#MySQL */
DECLARE x decimal (20,10);
DECLARE pi decimal (21,20);
SET pi = 3.14159265358979323846;
SET x = sin( lat1 * pi/180 ) * sin( lat2 * pi/180 ) + cos(
lat1 *pi/180 ) * cos( lat2 * pi/180 ) * cos( abs( (lon2 * pi/180) -
(lon1 *pi/180) ) );
SET x = acos( x );
RETURN ( 1.852 * 60.0 * ((x/pi)*180) ) / 1.609344;
END

最佳答案

准确的方法在这里

    public static double elongation(double longitude1, double latitude1, 
double longitude2, double latitude2)
{
return Math.Acos(1 - 2 * (hav(latitude1 - latitude2)
+ Math.Cos(RAD * latitude1) * math.Cos(RAD * latitude2)
* hav(longitude1 - longitude2))) / RAD;
}

当函数“hav”为

    static public double hav(double x)
{
return 0.5 - 0.5 * Math.Cos(RAD * x);
}

关于mysql - 获取地球上两个坐标之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32929008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com