T-SQL:在地图网格上查找对象的最接近位置 [英] T-SQL: Finding the closest location of an object on a map grid
问题描述
我在地图上显示了网格.我知道您的位置以及地图上2个对象的位置.对象出现在网格线相交的位置.考虑到世界是平坦的而不是圆形的,因为地图上的区域只有很短的距离.由于性能原因,我不想使用三角函数和乘法来确定最接近您的对象.我并不是在寻找准确性,而不仅仅是获得大致目标.我应该能够确定距当前位置的经纬度差之间的最短距离.我的表格位置"如下所示:
I have grid showing on a map. I know your location and the location of 2 objects on the map. Objects appear where grid lines cross. Consider the world flat and not round since the area on the map is only a short distance. I want to determine which object is closest to you without using trigonometry and multiplication for performance reasons. I'm not looking for accuracy as much as just getting a ballpark indication. I should be able to determine the shortest distance between the difference in latitude and longitude from my current location. My table, Locations, looks like this:
ID Latitude Longitude
1 50 70
2 30 40
如果我的位置是经度= 40,经度= 60,那么ID = 1的位置就离我更近了.
If my location is Latitude = 40 and Longitude = 60, then the location with ID = 1 would be closer to me.
如果我的位置是纬度= 30"和经度= 60",则可能两个位置的距离大致相同,因此只需选择一个即可.
If my location is Latitude = 30 and Longitude = 60, probably both locations are about the same distance, so just pick one.
如果我的位置是经度= 30,经度= 50,则ID = 2的位置会更近.
If my location is latitude = 30 and Longitude = 50, then the location with ID = 2 would be closer.
推荐答案
我只计算差值的总和.我尝试了一下,效果很好.
I would just do a min of the sum of the differences. I tried it out,and it works pretty well.
SELECT MIN(ABS(s.Latitude - 47) + ABS(s.Longitude - -122)), s.ID FROM Sites as s Group By ID;
这篇关于T-SQL:在地图网格上查找对象的最接近位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!