当前位置:Gxlcms > 数据库问题 > 利用SQL计算两个地理坐标(经纬度)之间的地表距离

利用SQL计算两个地理坐标(经纬度)之间的地表距离

时间:2021-07-01 10:21:17 帮助过:77人阅读

A点坐标(#{longitude},#{latitude}),B点坐标(longitude,latitude),若有一个坐标值为空则距离默认为100万公里(一个不合理的值) SELECT IF((ISNULL(#{latitude}) || LENGTH(trim(#{latitude})) < 1 || ISNULL(latitude) || LENGTH(trim(latitude)) < 1), 1000000, ROUND( 6378.137 * 2 * ASIN( SQRT( POW(SIN((#{latitude} * PI() / 180 - latitude * PI() / 180) / 2), 2) + COS(#{latitude} * PI() / 180) * COS(latitude * PI() / 180) * POW(SIN((#{longitude} * PI() / 180 - longitude * PI() / 180) / 2),2) ) ), 2) ) AS distance, name, photo_url photoUrl, address, telephone, latitude latitude, longitude longitude FROM store WHERE void_flag = 1 ORDER BY distance,code ASC

 :)

利用SQL计算两个地理坐标(经纬度)之间的地表距离

标签:order   地图   表示   segment   code   inf   技术   image   http   

人气教程排行