栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Haversine公式使用SQL Server查找最接近的场所-vb.net

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Haversine公式使用SQL Server查找最接近的场所-vb.net

我认为您最好将其放入UDF并在查询中使用它:

SELECt v.lat, v.lng, v.name, p.lat, p.lng, p.postpre, udf_Haversine(v.lat, v.lng, p.lat, p.lng) AS distance FROM venuepostpres v, postpreLngLat p WHERe p.outpre = 'CB6' ORDER BY distancecreate function dbo.udf_Haversine(@lat1 float, @long1 float, @lat2 float, @long2 float) returns float begin        declare @dlon float, @dlat float, @rlat1 float, @rlat2 float, @rlong1 float, @rlong2 float, @a float, @c float, @R float, @d float, @DtoR float        select @DtoR = 0.017453293        select @R = 3937 --3976        select  @rlat1 = @lat1 * @DtoR, @rlong1 = @long1 * @DtoR, @rlat2 = @lat2 * @DtoR, @rlong2 = @long2 * @DtoR        select  @dlon = @rlong1 - @rlong2, @dlat = @rlat1 - @rlat2        select @a = power(sin(@dlat/2), 2) + cos(@rlat1) * cos(@rlat2) * power(sin(@dlon/2), 2)        select @c = 2 * atn2(sqrt(@a), sqrt(1-@a))        select @d = @R * @c        return @d     end


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/614400.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号