大量位置地理编码的策略

发布于 2024-08-09 00:34:24 字数 356 浏览 1 评论 0原文

我有一个应用程序,它使用 Google 地图 API 对纬度/经度对之间的距离进行地理编码,以此在手机上显示您附近的人(目前为 Android,可在 iPhone 上运行)。问题是,即使测试组有 40 个用户,我们也需要花费 10 秒以上的时间来进行计算并将结果发送回用户。虽然 10 秒听起来很长,但就客户端应用程序而言,这并不是真正的问题,因为它不是实时更新人们的位置(每隔几分钟更新一次)。显然这是一个问题,因为我们显然希望增加到数万甚至数十万用户。我很好奇是否有其他人在这个领域有关于使用 Google Maps API 计算大量数据的点之间的距离的经验?

顺便说一句,我们在服务器上使用 Rails,这是所有位置计算发生的地方。手机仅显示地图并用纬度/经度坐标更新服务器。

I have an application that uses the Google Maps API to geocode distances between lat/long pairs as a way of displaying people near to you on your phone (currently Android, working on iPhone). The issue is that even with a test group of 40 users, we are taking upwards of 10 seconds to do our calculations and send the results back to the users. While 10 seconds sounds like a long time, it's not really an issue as far as the client app goes because it's not a real-time update of people's locations (the updates occur every few minutes). Obviously this is a problem though since we'd obviously love to ramp up to tens or even hundreds of thousands of users. I'm curious if anyone else has any experience in this arena in regards to using the Google Maps API for calculating distances between points for large volumes of data?

As an aside, we're using Rails on the server, which is where all of the location calculations are occurring. The phone(s) are merely displaying the maps and updating the server with lat/long coordinates.

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

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

发布评论

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

评论(3

北风几吹夏 2024-08-16 00:34:24

当您已经有了纬度/经度坐标时,您不需要谷歌地图 API 来计算距离。可以使用半正矢或文森蒂公式计算大圆距离

编辑:如果我正确理解您的问题(在 10,000 条记录中查找距离给定位置较近的位置),我只能建议使用一些地理库来实现此目的。当收到更多请求时,计算 10k 距离是一个坏主意。您绝对应该为此研究更智能的算法(四叉树似乎很实用)。

You do not need the google maps API to calculate distances when you already have lat/lon coordinates. Calculating the great-circle distance can be done using haversine or vincenty formula.

Edit: If I understand your problem correctly (finding close locations to one given location in 10,000 records) I can only recommend using some geo library for this purpose. Calculating 10k distances is a bad idea when more requests are coming in. You should definitely look into smarter algorithms for that (a quad tree seems practical).

安穩 2024-08-16 00:34:24

看看 Geokit,它是一个 Ruby Gem 和 Rails 插件,可以做你想做的事情,甚至更多,我我想您也会对速度和功能感到非常满意。

Take a peek at Geokit, it is a Ruby Gem and Rails plugin to do what you want and more, I think you'll be very happy with the speed and features as well.

薆情海 2024-08-16 00:34:24

如果您覆盖特定区域,您可能需要考虑在进行任何计算之前将经纬度转换为局部等距投影。或者更简单地说,如果覆盖全球区域,请将经纬度转换为两个最近的 UTM 区域,存储两组 XY 坐标和两个 UTM 区域 ID。然后,您可以首先选择 UTM 区域匹配上的记录,然后使用投影坐标对该子集进行计算(这比计算经纬度距离要快得多)。

You might want to considered converting lat long to a localized equidistant projection before doing any calculations if you are covering a specific area. Or more simply if covering global areas, convert the lat long to the two nearest UTM zones, storing two sets of X Y coordinates and the two UTM zones IDs. Then you can select records on UTM zone matches first, and carry out your calculations against that subset using the projected coordinates second (which will be significantly faster than calculating distance from lat long).

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