使用 MySQL 空间能力或经纬度查找 Rails 3“商店定位器”功能?

发布于 2024-10-04 05:40:35 字数 442 浏览 0 评论 0原文

我有一个 Rails 3 应用程序,并且有几个用例需要支持。

  • 给定地址或邮政编码的商店定位器。

  • 以图形方式显示用户的来源。

对于第一个,我需要“在哪里购买”类型的函数的速度和准确性。

对于第二个,我不需要非常准确的数据,采用 IP 服务返回的任何内容就足够了。我基本上想放一张谷歌地图,上面插着一堆别针。

我现在在这方面的经验为零。我很高兴编写 Javascript,并且我已经安装了 GeoKit 来进行地理编码(我可以拼写这个词,但我还不太理解)。我感谢您提供的任何帮助。

我知道 MySQL 有空间扩展,并且更新看起来非常简单。也许这是一个分裂决策,我使用空间信息来存储商店位置,然后从用户的 IP 地址获取用户的位置。

对于站点使用用例,实时扫描日志文件或将命中存储在数据库中更有意义吗?

I have a Rails 3 application and I have a couple of use cases to support.

  • Store Locator given an address or zip code.

  • Graphical display of where users are originating from.

On the first one, I need speed and accuracy for a "Where to Buy" type of function.

On the second one, I don't need super accurate data, taking whatever the IP service returns is good enough. I basically want to put up a Google map with a bunch of pins stuck in it.

I have zero experience in this right now. I'm happy to write Javascript, and I have installed GeoKit to do the geocoding (a word which I can spell but which I don't really understand yet). I appreciate any help you can offer.

I know MySQL has spatial extensions and the updates look like they would be really simple. Maybe this is a split decision where I use the spatial information to store the store locations, then just get the location of a user from their IP address.

For the site usage use case, does it make more sense to scan a log file live, or to store hits in a database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

流心雨 2024-10-11 05:40:35

地理编码是将地址或邮政编码等内容转换为纬度/经度坐标。

我使用 Google 的地理编码 API,但每天的请求数限制为2,500,除非您是 Google Maps API Premier 用户。它非常快(几乎我的 Rails 应用程序发出的每个请求都需要不到 0.1 秒)并且准确。不过请阅读一下,因为有更多有关地理编码的信息。

我使用从地理编码返回的纬度/经度来查询我的 MySQL 数据库,这是一个有点昂贵的查询,但在我相当小的表(大约 10,000 个具有纬度/经度值的对象)上仍然执行得非常快(同样,不到 0.1 秒) 。这是我使用的查询(将 {LAT} 和 {LNG} 替换为您的纬度和经度值):

SELECT
whatever, 3963.191 * ACOS((SIN(RADIANS({LAT}))*SIN(RADIANS(lat))) +(COS(RADIANS({LAT}))*cos(RADIANS(lat))*COS(RADIANS(lng)-RADIANS({LNG})))) AS distance
FROM things
HAVING distance < 30
ORDER BY distance;

Geocoding is converting something like an address or zip code to lat/long coordinates.

I use Google's Geocoding API, though the limit on the number of requests/day is 2,500 unless you're a Google Maps API Premier user. It's very fast (nearly every request my Rails app makes takes less than 0.1 seconds) and accurate. Have a read though, as there's more info on what geocoding is.

I use the lat/long returned from geocoding to query my MySQL database, which is a somewhat-expensive query but still executes very quickly (again, less than 0.1 seconds) over my reasonably small table (around 10,000 objects with lat/long values). Here's a query I use (replace {LAT} and {LNG} with your lat and long values):

SELECT
whatever, 3963.191 * ACOS((SIN(RADIANS({LAT}))*SIN(RADIANS(lat))) +(COS(RADIANS({LAT}))*cos(RADIANS(lat))*COS(RADIANS(lng)-RADIANS({LNG})))) AS distance
FROM things
HAVING distance < 30
ORDER BY distance;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文