我有一个位置(纬度和经度)。如何获取部分或全部位于我所在位置 10 英里半径范围内的邮政编码列表?
该解决方案可以是调用众所周知的 Web 服务(google 地图、bing 地图等)或本地数据库解决方案(客户端有 sql server 2005)或算法。
我已经看到了一些类似的问题 https://stackoverflow.com/questions/3919878/how-to-return-all-instances-within-mile-radius-of-a-list-of-zipcodes,但那里的所有答案几乎都与使用我无法使用的 SQL Server 2008 地理功能有关。
从包含邮政编码及其相应的纬度和经度坐标的邮政编码数据库开始:
http://www.zipcodedownload.com/Products/Product/Z5Commercial/Standard/Overview/ http://www.zipcodedownload.com/Products/Product/Z5Commercial/Standard/Overview/
要获得纬度和经度之间的距离,您需要一个好的距离公式。该网站有几个变体:
http://www.meridianworlddata.com/distance-calculation/ https://web.archive.org/web/20181101034427/http://www.meridianworlddata.com/distance-calculation/
“大圆距离”公式有点极端。根据我的经验,这个效果很好:
sqrt(x * x + y * y)
where x = 69.1 * (lat2 - lat1)
and y = 69.1 * (lon2 - lon1) * cos(lat1/57.3)
您的 SQL 查询将如下所示:
select zd.ZipCode
from ZipData zd
where
sqrt(
square(69.1 * (zd.Latitude - @Latitude)) +
square(69.1 * (zd.Longitude - @Longitude) * cos(@Latitude/57.3))
) < @Distance
祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)