2013-06-13 187 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有詳細的介紹
相關問題