简体   繁体   English

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

[英]How can I search based on distance with the Google Maps API?

  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). 所以这就是问题...我有一个字段,用户可以输入他们的地址(将通过Google Maps API进行GeoCoded)。
  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. 谢谢。

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

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. 点击这里他们提供了几种计算距离的方法 - 选择最适合你的方法。

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. A /作为点或感兴趣的位置是通过您的网站的客户的意见,收集地理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. B /使用谷歌进行批量地理编码,也许一次一个,最后我看到每个网站的IP地址最多5000个。 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. C /使用地理编码服务购买合同,并存储他们为您进行地理编码的内容。

D/ Purchase a geocoding library and do your own geocoding. D /购买地理编码库并进行自己的地理编码。

此博客文章“使用Google Maps API计算距离”可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM