你如何知道邻近的邮政编码是什么?

发布于 2024-07-30 17:52:13 字数 130 浏览 11 评论 0原文

我遇到的情况与职位搜索引擎中的情况类似,您输入要搜索职位的邮政编码,应用程序会返回该邮政编码以及邮政编码 5、10、15 中的职位,距离该邮政编码 20 或 25 英里,具体取决于用户设置的偏好。

如何计算邮政编码的邻近位置?

I have a situation that's similar to what goes on in a job search engine where you type in the zipcode where you're searching for a job and the app returns jobs in that zipcode as well as in zipcodes that are 5, 10, 15, 20 or 25 miles from that zipcode, depending on preferences set by the user.

How would you calculate the neighboring locations for a zipcode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

孤檠 2024-08-06 17:52:13

您需要获取具有关联经度/纬度坐标的邮政编码列表。 Google it - 有很多提供商。

然后看看这个问题的算法如何计算距离

You need to get a list of zip codes with associated longitude / latitude coordinates. Google it - there are plenty of providers.

Then take a look at this question for an algorithm of how to calculate the distance

£噩梦荏苒 2024-08-06 17:52:13

我不知道您是否可以指望 geonames.org 在您的应用程序的生命周期中一直存在,但您可以使用像他们这样的网络服务来避免重新发明轮子。

http://www.geonames.org/export/web-services.html

I don't know if you can count on geonames.org to be around for the life of your app but you could use a web service like theirs to avoid reinventing the wheel.

http://www.geonames.org/export/web-services.html

不知在何时 2024-08-06 17:52:13

我不会计算它,我会将其存储为数据库中的固定表(仅当一个国家/地区的邮政编码分配发生变化时才会更改)。 建立一个关系“is_neighbor_zip”,它有对(更小,更大)。 要确定两个代码是否相邻,请在表中检查特定对。 如果您想要所有相邻的拉链,最好使表格对称。

I wouldn't calculate it, I would stored it as a fixed table in the database (only to change when the allocation of ZIP codes changes in a country). Make a relationship "is_neighbor_zip", which has pairs (smaller, larger). To determine whether two codes are neighboring, check in the table for specific pair. If you want all neighboring zips, it might be better to make the table symmetric.

影子是时光的心 2024-08-06 17:52:13

您需要使用 GIS 数据库并询问您当前位置附近的邮政编码。

您不能简单地获取邮政编码并应用一些数学计算来查找附近的其他邮政编码。 邮政编码不像美国的区号那样在地理上分散,但它们不是坐标系。

唯一的例外是 ZIP+4 代码是较大邮政编码的子部分。 您可以假设具有相同邮政编码的任何 ZIP+4 代码都彼此接近。

我曾经在一家公司致力于合理化邮政编码处理,以下是我所做的一些实用笔记:

测试邮政编码

希望有其他有用的信息。

You need to use a GIS database and ask it for ZIP codes that are nearby your current location.

You cannot simply take the ZIP code number and apply some mathematical calculations to find other nearby ZIP codes. ZIP codes are not as geographically scattered as area codes in the US, but they are not a coordinate system.

The only exception is that the ZIP+4 codes are sub-sections of the larger ZIP code. You can assume that any ZIP+4 codes that have the same ZIP code are close to each other.

I used to work on rationalizing the ZIP code handling at a company, here are some practical notes I made:

Testing ZIP codes

Hopefully has other useful info.

忘东忘西忘不掉你 2024-08-06 17:52:13

每当您创建邮政编码时,对其进行地理编码(例如,谷歌地理编码器API,保存纬度和经度),然后谷歌搜索半正弦公式,这将计算距参考点的距离(如乌鸦飞翔),如果是的话,也可以对其进行地理编码城镇或邮政编码。

为了澄清更多:

当您根据位置检索记录时,您需要将每个经度和纬度 DECIMAL 与参考点(您的用户地理编码的邮政编码或城镇名称)进行比较

您可以查询:

SELECT * FROM photos p WHERE p.long < 60 AND p.long > 50 AND p.lat > -10 AND p.lat > 10

要查找所有英国照片等,因为英国在 50 到 60 度经度和 +-10 纬度之间(我可能已经用纬度切换了长距离,我对此很模糊)

如果你想找到距离,那么你需要谷歌搜索半正矢公式并插入你的参考值。

希望这能让事情变得更清楚,如果您需要详细信息,请发表评论

Whenever you create a zipcode, geocode it (e.g. google geocoder api, saving the latitude and logitude) then google the haversine formular, this will calculate the distance (as the crow flies) from a reference point, which could also be geocoded if it is a town or zipcode.

To clarify some more:

When you are retrieving records based on their location, you need to compare each longitude and latitude DECIMAL with a reference point (your users geo-coded postcode or town name)

You can query:

SELECT * FROM photos p WHERE p.long < 60 AND p.long > 50 AND p.lat > -10 AND p.lat > 10

To find all UK photos etc because the uk is between 50 and 60 degrees longitude and +-10 latitude (i might have switched long with lat, i'm fuzzy on this)

If you want to find the distance then you will need to google the haversine formula and plug in your reference values.

Hope this clears things up a little bit more, leave a comment if you need details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文