如何使用 Google Maps API 根据距离进行搜索?

发布于 2024-08-25 04:05:41 字数 225 浏览 6 评论 0原文

  1. 所以这就是问题......我有一个字段,用户可以在其中输入他们的地址(将通过 Google 地图 API 进行地理编码)。
  2. 我的数据库中有几个小部件的地址(另存为地址..再次可以轻松进行地理编码)。

我需要的是用户输入他们的地址,并根据距他们地址的距离显示我的小部件列表。我的小部件有数千个地址,而用户显然有无数个地址。

有什么想法吗?

谢谢。

  1. So here's the issue... I have a field where users can type in their address (which will be GeoCoded via Google Maps API).
  2. 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 技术交流群。

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

发布评论

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

评论(4

为人所爱 2024-09-01 04:05:41
SELECT latitude, longitude, SQRT( POW( 69.1 * ( latitude - 52.58 ) , 2 ) + 
POW( 69.1 * ( - 1.12 - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance 
FROM location ORDER BY distance

单击此处
它们提供了多种计算距离的方法 - 选择最适合您的方法。

SELECT latitude, longitude, SQRT( POW( 69.1 * ( latitude - 52.58 ) , 2 ) + 
POW( 69.1 * ( - 1.12 - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance 
FROM location ORDER BY distance

Click Here
They provide several ways of calculating the distance - choose what works best for you.

£冰雨忧蓝° 2024-09-01 04:05:41

如果您将项目存储在 MySQL 数据库中,那么这是您需要的基础

If you are storing the items in a MySQL DB, then here's the basis what you need

怀中猫帐中妖 2024-09-01 04:05:41

你真的不能使用谷歌来计算你的地理距离过滤。为此,您必须向他们发送您的数据,让他们存储并为您查询。他们现在或将来可能会提供这项服务,但我还没有听说过。

按照更合法、更有能力、更昂贵的顺序:

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.

神经暖 2024-09-01 04:05:41

这篇博文“使用 Google 计算距离Maps API”,可能会有所帮助。

This blog post, "Calculate Distance using Google Maps API", may be of some assistance.

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