2013-07-09 50 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

相关问题