如何使用Google Maps API根据距离进行搜索?(How can I search based on distance with the Google Maps API?)
所以这就是问题......我有一个字段,用户可以输入他们的地址(通过Google Maps API进行GeoCoded)。
我的数据库中有几个小部件地址(保存为地址..再次可以轻松地进行地理编码)。
我需要的是让用户输入他们的地址,并根据他们地址的距离输入我的小部件列表。 我的小部件有数以万计的地址,用户显然拥有无限数量的地址。
有任何想法吗?
谢谢。
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.
最满意答案
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 distanceClick Here They provide several ways of calculating the distance - choose what works best for you.
更多推荐
发布评论