PHP MySQL 最接近邮政编码
您好,我发现这篇文章很有帮助,但不幸的是我无法让它发挥作用。
http:// davidsimpson.me/2008/09/28/find-nearest-store-page-using-php-mysql-and-google-maps/
我在 MySQL 表中有一个商店列表邮政编码、经度、纬度和各种其他存储特定信息。
我希望用户能够在表单上输入他们的邮政编码,指定以英里为单位的最大距离(即下拉菜单,10 英里内,20 英里内等),然后按顺序提取结果MySQL 数据库。
任何人都可以阐明这一点吗?
问候
Hello I found this article which is helpful but unfortunately I cannot get it to work.
http://davidsimpson.me/2008/09/28/find-nearest-store-page-using-php-mysql-and-google-maps/
I have a list of stores in a MySQL table with postcode,longitude,latitude and various other store specific information.
I'd like the user to be able to enter their postcode on a form, specify a maximum distance in miles (ie a drop down menu, within 10 miles, within 20 miles etc), then for the results to be pulled in order from MySQL database.
Can anybody shed some light on this.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然该示例中提供的方法可以发挥作用,但它必须计算表中每一行的距离。当大规模工作时,这效率太低了。看看本教程 。它使用MySQL中的特殊数据类型作为坐标,并且可以非常快速地搜索。希望它能为您提供从哪里开始的基础。
您的解决方案可能更加简单。它将需要所有邮政编码的列表以及所有商店的列表。由于所有输入和输出都是已知因素,因此您可以将其预先计算到“缓存”表中,这将为您提供非常快速的结果。创建一个名为 StoreDistances10Miles 的表(猜测数据类型和命名约定):
迭代每个邮政编码,按距离对商店进行排序,并将 10 英里以内的商店保存到表中。现在,当您想按邮政编码搜索时,只需按邮政编码搜索 StoreDistances10Miles 即可获得列表。确保您索引了
邮政编码
。您需要为您想要在网站上提供的每个距离重新生成一个表格。
While the approach offered in that example will function, it has to calculate the distance for every row in the table. This is simply too inefficient when working at scale. Have a look at this tutorial. It uses special data types in MySQL for the coordinates and can search very quickly. It should hopefully give you a grounding on where to start.
Your solution may be even more straightforward. It is going to require a list of all the postcodes and also a list of all the stores. As all your inputs and outputs are known factors, you can pre calculate this into "cache" tables which would give you very fast results. Create a table called StoreDistances10Miles (guessing on data types and naming conventions):
Iterate over each postcode, sort the stores by distance and save the ones within 10 miles into the table. Now, when you want to search by postcode, just search StoreDistances10Miles by postcode and you'll have your list. Make sure you index
postcode
.You'll need to reproduce a table for each distance you want to offer on your site.
好吧,他清楚地给出了如何获取里程,因此您需要使用下拉菜单将“拥有里程 < {dropdownvalue}”添加到您的 sql 语句中。因此,如果您有 10 英里,那么它的英里数 < 10 等
Well he clearly gives how to get the miles, so all you need to have using your drop down is "Having miles < {dropdownvalue}" added to your sql statement. so if you have 10 miles, its having miles < 10 etc.