MySQL PHP邮政编码比较具体距离
我试图找出比较一个邮政编码(用户提供的)和一大堆其他邮政编码(现在大约有 200 个邮政编码)之间的距离的最有效方法(相对于加载时间) ,但它会随着时间的推移而增加)。我不需要任何精确的东西,只是在球场上。
我下载了整个美国的邮政编码 csv 文件,并且我有一个函数可以生成两个邮政编码之间的距离(我相信以弧度为单位)。我不需要显示距离,我只需要对200 个邮政编码,最接近的为第一个结果。
我将 csv 文件上传到 mysql 表。我想我可以循环遍历所有 200 个邮政编码,并为每个邮政编码更新一个包含距离的字段。然后使用 ORDER BY,从最近到最远对它们进行排序。
有谁知道更有效的方法来做到这一点?这种方式需要在每次运行搜索查询时更新整个邮政编码数据库。现在只有 200 个邮政编码,这不是什么大问题,但我想它会减慢数据库构建时的加载时间。提前感谢您的任何建议,非常感谢!
I'm trying to figure out what would be the most efficient (with respect to load time) to compare the distance between one zip code (which the user provides) and a whole bunch of other zip codes (there's approximately 200 zip codes right now, but its subject to increase over time). I don't need anything exact just in the ball park.
I downloaded a zip code csv file for all of the US, and I've got a function which produces the distance between two zip codes (in radians i believe.) I don't need to display the distance i just need to sort the 200 zip codes with the closest being the first of the results.
I uploaded the csv file to a mysql table. I was thinking I could cycle through all the 200 zip codes, and update a field for each one containing the distance. Then using ORDER BY, sort them from closest to furthest.
Does anyone know of a more efficient way to do this? This way would require updating the entire db of zip codes every time a search query is run. With only 200 zip codes its not a big deal now, but i imagine it will slow down the load time as the db builds. Thanks ahead for any advice, its much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Javascript 中:
其中 d = 两点之间的距离
这是 Haversine 公式。
In Javascript:
where d = distance between two points
This is the Haversine formula.