从一系列可能的位置中找到最佳的经度/纬度匹配

发布于 2024-10-10 06:42:22 字数 508 浏览 0 评论 0原文

我有一个包含 12 个具有唯一键的对象的 plist(比方说 1、2、3 等)。每个对象都包含一个包含 100 - 200 个对象的数组(键:clubLocations)。

clubLocations 数组中的每个对象都包含一个 longitudelatitude 键以及俱乐部的位置。

我需要一些帮助来创建一个方法,该方法循环遍历每个对象对于每个clubLocations12个对象并找出哪个clubLocation是最接近的与用户坐标匹配。

所以基本上反对 1/2/3/etc -> ClubLocations objectAtIndex:0/1/2/3/etc ->最佳匹配?

我有用户的坐标,所以“只是”需要帮助从我的 plist 中找到最近的位置。预先感谢您,如果我说得不够清楚,请随时在评论中询问。

I have a plist with 12 objects with unique keys (let's say 1, 2, 3, etc). Each object contains an array (key: clubLocations) with 100 - 200 objects.

Each object in the clubLocations array contains a longitude and latitude key with a club's location.

I would like some assistance in creating a method which loops through each object for every clubLocations in every 12 objects and finds out which clubLocation is the closest match to the users coordinates.

So basically object 1/2/3/etc -> clubLocations objectAtIndex:0/1/2/3/etc -> best match?

I have the user's coordinates, so "just" need assistance to find the closest locations from my plist. Thank you in advance and please do not hesitate to ask in a comment if I am not making myself clear enough.

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

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

发布评论

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

评论(1

黎歌 2024-10-17 06:42:22

在伪代码中:

min_distance = MAXINT
closest = None
for obj in objects:
  for club in obj.clubLocations:
    d = distance(club.longitude, club.latitude, user.longitude, user.latitude)
    if d < min_distance:
      min_distance = d
      closest = club

In pseudocode:

min_distance = MAXINT
closest = None
for obj in objects:
  for club in obj.clubLocations:
    d = distance(club.longitude, club.latitude, user.longitude, user.latitude)
    if d < min_distance:
      min_distance = d
      closest = club
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文