如何利用邮政编码实现邻近搜索?

发布于 2024-08-13 07:52:26 字数 842 浏览 3 评论 0 原文

我必须使用带有澳大利亚邮政编码的邻近搜索。通过一些链接,例如 http://www.randommouse.com/rms/about/product/FNDRY/docs/tutorial/08/how-to-add-google-maps-to-your-review-site- intro.html

如果我没有记错的话,我发现我必须用纬度和经度来管理邮政编码。但我找不到如何实现这一点。任何人都可以建议我如何使用 php 执行此操作或提供一些链接,以便我可以看到更多相关内容。

提前致谢。

已编辑:

我已编辑了我的问题:

我可以使用 google api 来获取给定范围内的邮政编码吗?我找到了 drupal 的链接。那么我可以使用 google api 来获取邮政编码吗?随后的链接是 http ://svendecabooter.be/blog/implementing-location-proximity-search-for-belgium-with-drupal-and-google-maps

I have to use proximity search with postcode for Australia. Going through some links like
http://www.randommouse.com/rms/about/product/FNDRY/docs/tutorial/08/how-to-add-google-maps-to-your-review-site-intro.html

I found that I have to manage the the post codes with latitude and longitude if I am not mistaken. But i could not find how to implement this. Can anyone suggest me how to do this with php or give some links so that i could see more on this.

Thanks in advance.

Edited:

I have edited my question:

Can I use google api for this i.e. to get the post codes within given range. I have found a link that is for the drupal. So can I use google api just to get postcodes. The link have followed is http://svendecabooter.be/blog/implementing-location-proximity-search-for-belgium-with-drupal-and-google-maps

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

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

发布评论

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

评论(3

寻梦旅人 2024-08-20 07:52:26

您需要找到一个包含每个邮政编码的经度和纬度的数据库。获得经度和纬度后,您将使用半正弦公式 (http://www.codecodex.com /wiki/Calculate_Distance_Between_Two_Points_on_a_Globe)来计算点之间的距离。要进行邻近搜索,您必须计算从起点到数据集中所有点的距离。您还可以考虑使用边界框,然后搜索该边界框内的点。像 PostGIS 这样的地理空间数据库内置了可以帮助解决所有这些问题的功能。

You'll need to find a database that has the longitude and latitude of each postal code. Once you have the longitude and latitude you'll use the havesine formula (http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe) to calculate the distance between points. To do a proximity search you'll have to calculate the distance from your starting point to all the points in your dataset. You may also consider using a bounding box and then searching for points inside that bounding box. A geo spatial database like PostGIS has built in functions that can help with all this.

单身狗的梦 2024-08-20 07:52:26

您可能还想看看 GeoHash 作为加速搜索长/纬度的方法在一个区域内(邻近)。有各种语言的“插件”,例如。 Ruby 中的 GeoHash 非常易于使用。

You might also want to look at GeoHash as a way to speed up searching for a long/lat within an area (proximity). There are 'plugins' in various languages eg. GeoHash in Ruby is very easy to use.

记忆で 2024-08-20 07:52:26

MySQL 还提供了执行简单地理距离计算的工具,这可能会有所帮助。
https://www.percona.com/blog/2013/10/21/using-the-new-spatial-functions-in-mysql-5-6-for-geo-enabled-applications/

获取最新的澳大利亚邮政编码数据可能是一个问题,因为 AusPost 不再免费提供最新列表。如果在 Google 地图中操作,则可以使用通过查询 Google 获取的数据来填充表。

我有一个带有邮政编码和纬度/经纬度的郊区列表,您可以在 下载http://www.computerpros.com.au/data/australian_suburbs.sql

这是一个具有以下表结构的 Mysql 转储:

+----------+----------------------+------+-----+---------+-------+
| Field    | Type                 | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| id       | int(10) unsigned     | NO   |     | 0       |       |
| name     | varchar(64)          | NO   |     | NULL    |       |
| postcode | varchar(4)           | NO   |     | NULL    |       |
| state    | smallint(5) unsigned | NO   |     | NULL    |       |
| lat      | float(10,6)          | NO   |     | NULL    |       |
| lng      | float(10,6)          | NO   |     | NULL    |       |
+----------+----------------------+------+-----+---------+-------+

MySQL also provides facility for performing simple Geo distance calculations which may help.
https://www.percona.com/blog/2013/10/21/using-the-new-spatial-functions-in-mysql-5-6-for-geo-enabled-applications/

Obtaining up-to-date Australian postcode data can be a problem since AusPost no longer provide the up-to-date list for free. If operating within Google Mapping then it should be OK to populate a table with data taken by querying the Google.

I have a list of suburbs with postcodes and lat/lngs that I use internally that you can download at http://www.computerpros.com.au/data/australian_suburbs.sql

This is a Mysql dump with the following table structure:

+----------+----------------------+------+-----+---------+-------+
| Field    | Type                 | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| id       | int(10) unsigned     | NO   |     | 0       |       |
| name     | varchar(64)          | NO   |     | NULL    |       |
| postcode | varchar(4)           | NO   |     | NULL    |       |
| state    | smallint(5) unsigned | NO   |     | NULL    |       |
| lat      | float(10,6)          | NO   |     | NULL    |       |
| lng      | float(10,6)          | NO   |     | NULL    |       |
+----------+----------------------+------+-----+---------+-------+
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文