如何使用Google Maps API根据距离进行搜索?(How can I search based on distance with the Google Maps API?)

编程入门 行业动态 更新时间:2024-10-28 05:28:09
如何使用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 distance

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

更多推荐

本文发布于:2023-07-31 13:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1345303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   距离   Maps   API   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!