2013-07-09 154 views
0

我目前正在爲iOS開發一個移動應用程序,其中包含需要確定用戶當前位置和從當前位置開始的部分,我想查找最近的位置。從我的當前位置獲取距離最近的位置

有沒有什麼辦法可以實現呢?

我已經做了一些編碼來找到用戶的當前位置。 這裏是我的代碼片段,

CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
    [geocoder reverseGeocodeLocation:locationManager.location 
        completionHandler:^(NSArray *placemarks, NSError *error) { 
         NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!"); 

         if (error){ 
          NSLog(@"Geocode failed with error: %@", error); 
          return; 

         } 

         CLPlacemark *placemark = [placemarks objectAtIndex:0]; 
         NSLog(@"placemarks=%@",[placemarks objectAtIndex:0]); 

但我的問題是,我將如何得到最近的其他地點?從我已經提取的當前位置。

在此先感謝。

+0

去[此鏈接](http://stackoverflow.com/questions/17085668/how-to-find-nearest-latitude-and-longitude-form當前位置),這有類似的問題。我想這會幫助你。 – Suryakant

回答

1

嘗試......

MKPointAnnotation *ann=[MKPointAnnotaion alloc] init]; 
CLLocationCoordinate2D point = [ann coordinate]; 
myLocation = [[CLLocation alloc] initWithLatitude:point.latitude longitude:point.longitude]; 
CLLocationDistance nearByLocation=[yourCurrentLocation distanceFromLocation:myLocation]; 
+0

如何初始化myLocation?和什麼來代替'yourCurrentLocation'?我已經寫了我的代碼片段上面的當前位置。 – Krunal

+0

檢查這[教程](http://mobileorchard.com/hello-there-a-corelocation-tutorial/)獲取當前位置 –

+0

老兄我得到當前的位置,但什麼來代替'yourCurrentLocation'?我寫了'locationManager.location'來代替'yourCurrentLocation'是不是? – Krunal

相關問題