2013-06-13 52 views
0

我有一个包含n个纬度,经度和地址集合的字典。我想计算哪些(纬度和lang度)点离当前用户位置(纬度,lang度)最接近ios?如何找到距离当前位置最近的经纬度?

在此先感谢

+1

“我计算哪个点离ios当前点最近?” - 我不知道你是否计算它。我目前不知道你在做什么。 – 2013-06-13 11:15:51

+0

想根据坐标来计算...? –

+0

是的,我想根据坐标计算 – sabeer

回答

0

的理解从属,这里是简单的场景: 只需从你的字典中获取所有"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,他们很好地达到完美。

0

这个问题类似于寻找K近邻(KNN)的问题。 我会建议你去通过以下链接会对如果要计算基于合作如何解决你的问题

  1. KNN Wiki
  2. blog有详细的介绍
相关问题