【问题标题】:how to find nearest latitude and longitude form current place?如何从当前位置找到最近的经纬度?
【发布时间】:2013-06-13 11:13:25
【问题描述】:

我有一本包含 n 个纬度、经度和地址的字典。我想计算ios中哪个(纬度和经度)点距离当前用户位置(纬度,经度)最近?

提前致谢

【问题讨论】:

  • "我计算 ios 中哪个点离当前点最近?" - 不知道你算不算。我不知道你目前在做什么。
  • 想根据坐标计算...?
  • 是的,我想根据坐标计算

标签: ios math ios6 core-location


【解决方案1】:

如果你想根据坐标进行计算,这里有一个简单的场景: 只需从您的字典中取出所有"CLLocationCoordinate2D"

例如:

MKPointAnnotation *annotaion=[MKPointAnnotaion alloc]alloc];

CLLocationCoordinate2D pointACoordinate = [annotation coordinate];
//  If you have the co-ordinates in hand , then just make " CLLocation *loc2; " using Co-ordinates  

loc2 = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude];

然后放循环或任何你想通过与所有使用这个比较来计算更小的距离

CLLocationDistance nearLocation=[ location distanceFromLocation:loc2]; // location --> your current Location

如果你想实现其他的:那就关注saury answer,他们可以完美实现。

【讨论】:

    【解决方案2】:

    这个问题类似于寻找 K 最近邻 (KNN) 问题。 我建议您通过以下链接了解如何解决您的问题

    1. KNN Wiki
    2. 很好 blog 有详细的概述

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      相关资源
      最近更新 更多