给定坐标,如何获取 10 英里半径内的所有邮政编码?
我有一个位置(纬度和经度)。如何获取部分或全部位于我所在位置 10 英里半径范围内的邮政编码列表?
该解决方案可以是调用众所周知的 Web 服务(google 地图、bing 地图等)或本地数据库解决方案(客户端有 sql server 2005)或算法。
我看到了一些类似的问题,但其中的所有答案几乎都与使用 SQL Server 2008 地理功能有关,而我无法使用该功能。
I have a location (latitude & longitude). How can I get a list of zipcodes that are either partially or fully within the 10 mile radius of my location?
The solution could be a call to a well known web service (google maps, bing maps, etc...) or a local database solution (the client has sql server 2005) or an algorithm.
I have seen the somewhat similar question, but all the answers there pretty much pertain to using SQL Server 2008 geography functionality which is unavailable to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从包含邮政编码及其相应纬度和经度坐标的邮政编码数据库开始:
http://www.zipcodedownload.com/Products/Product/Z5Commercial/Standard/Overview/
要获取纬度和经度之间的距离,您需要一个好的距离公式。该网站有几个变体:
http: //www.meridianworlddata.com/distance-calculation/
“大圆距离”公式有点极端。根据我的经验,这个效果很好:
然后你的 SQL 查询将如下所示:
祝你好运!
Start with a zip code database that contains zipcodes and their corresponding latitude and longitude coordinates:
http://www.zipcodedownload.com/Products/Product/Z5Commercial/Standard/Overview/
To get the distance between latitude and longitude, you will need a good distance formula. This site has a couple variations:
http://www.meridianworlddata.com/distance-calculation/
The "Great Circle Distance" formula is a little extreme. This one works well enough from my experience:
Your SQL Query will then look something like this:
Good luck!
首先,您需要一个包含所有邮政编码及其相应纬度和经度的数据库。在澳大利亚,只有几千个(而且信息很容易获得),但我认为这在美国可能是一项更困难的任务。
其次,如果您知道自己所在的位置,并且知道要查找的半径,则可以查找该半径内的所有邮政编码。用 PHP 编写的简单内容如下:(抱歉,它不是用 C# 编写的)
Firstly, you'll need a database of all zipcodes and their corresponding latitudes and longitudes. In Australia, there are only a few thousand of these (and the information is easily available), however I assume it's probably a more difficult task in the US.
Secondly, given you know where you are, and you know the radius you are looking for, you can look up all zipcodes that fall within that radius. Something simple written in PHP would be as follows: (apologies it's not in C#)
大多数搜索都使用质心。为了使用 10 英里内的部分邮政编码,您必须购买邮政编码多边形数据库 (*)。然后实施一种算法,检查顶点在 10 英里半径内的邮政编码。为了正确完成,您应该使用半正矢公式进行距离测量。通过一些巧妙的数据结构,您可以显着减少搜索空间。同样,通过存储并最初与 zipcoe 范围(北、西、东、南)进行比较,可以大大加快搜索速度。
(*) 注意:从技术上讲,邮政编码不是多边形!我知道我们都这样认为它们,但实际上它们是数据点(街道地址)的集合,这就是 USPS 真正使用它们的方式。这意味着邮政编码可以包含其他邮政编码;邮政编码可以由多个“多边形”组成;并且邮政编码可以与其他邮政编码重叠。大多数情况应该不是问题,但您必须处理可以定义为多个多边形的邮政编码。
Most searches work with centroids. In order to work with partial zipcodes being within the 10 miles, you are going to have to buy a database of zipcode polygons (*). Then implement an algorithm which checks for zipcodes with vertices within your 10 mile radius. To be done properly, you owuld use the Haversine formula for the distance measurement. With some clever data structures, you can significant reduce the search space. Similarly, searches can be greatly speeded up by storing and initially comparing against zipcoe extents (North,West,East,South).
(*) Note: Technically zipcodes are NOT polygons! I know we all think of them like that, but really they are collections of data points (street addresses) and this is how the USPS really uses them. This means zipcodes can include other zipcodes; zipcodes can be made of multiple "polygons"; and zipcodes can overlap other zipcodes. Most of these situations should not be a problem, but you will have to handle zipcodes that can be defined as multiple polygons.