如何使用 Google Maps API 根据距离进行搜索?
- 所以这就是问题......我有一个字段,用户可以在其中输入他们的地址(将通过 Google 地图 API 进行地理编码)。
- 我的数据库中有几个小部件的地址(另存为地址..再次可以轻松进行地理编码)。
我需要的是用户输入他们的地址,并根据距他们地址的距离显示我的小部件列表。我的小部件有数千个地址,而用户显然有无数个地址。
有什么想法吗?
谢谢。
- So here's the issue... I have a field where users can type in their address (which will be GeoCoded via Google Maps API).
- I have several addresses of widgets in my database (saved as address.. again can easily be geocoded).
What I need is for the user to type in their address and for a list of my widgets to come up based on distance from their address. I have THOUSANDS of addresses for my widgets and users have an infinite number of addresses obviously.
Any ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
单击此处
它们提供了多种计算距离的方法 - 选择最适合您的方法。
Click Here
They provide several ways of calculating the distance - choose what works best for you.
如果您将项目存储在 MySQL 数据库中,那么这是您需要的基础
If you are storing the items in a MySQL DB, then here's the basis what you need
你真的不能使用谷歌来计算你的地理距离过滤。为此,您必须向他们发送您的数据,让他们存储并为您查询。他们现在或将来可能会提供这项服务,但我还没有听说过。
按照更合法、更有能力、更昂贵的顺序:
A/ 当您网站的客户输入单个点或感兴趣的位置时,收集地理坐标。然后使用您自己的搜索引擎并按距某个点的距离进行搜索。可能违反了与谷歌的协议,但他们确实提到了“缓存”结果以减轻服务器的负载。 (原因是我个人的猜测。)
B/ 使用 google 进行批量地理编码,也许一次一个,每天最多对我上次看到的站点 IP 地址进行 5000 个地理编码。甚至不确定这是否违反使用协议。
C/ 购买地理编码服务合同,并存储他们为您进行地理编码的内容。
D/ 购买地理编码库并进行自己的地理编码。
You really CAN'T use google to calculate your geo distance filtering. To do that, you would have to send them YOUR data, have them store it, and query it for you. They may offer that service, now, or in the future, but I haven't heard of it.
In order of more legal, more capable, more expensive:
A/ As SINGLE points or locations of interest are input by customers of your site, collect the geo coordiniates. Then use your own search engine and search by distance from a point. MAY be a violation of the agreement with google, but they do mention 'caching' results to take the load off their servers. (The reason is my personal guess.)
B/ Use google to do bulk geocoding, perhaps ONE AT A TIME, to a max of 5000 per day per your site's IP Address last I saw. Not even sure if that is not a violation of the use agreement.
C/ Purchase a contract with a geocoding service, and store what they geocode for you.
D/ Purchase a geocoding library and do your own geocoding.
这篇博文“使用 Google 计算距离Maps API”,可能会有所帮助。
This blog post, "Calculate Distance using Google Maps API", may be of some assistance.