【问题标题】:get nearest locations from my current location从我当前的位置获取最近的位置
【发布时间】:2013-07-09 09:58:27
【问题描述】:

我目前正在为 iOS 开发一个移动应用程序,其中包含需要确定用户当前位置的部分,我想从当前位置找到最近的位置。

有没有办法实现这个??

我已经编写了一些代码来查找用户的当前位置。 这是我的代码 sn-p,

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]);

但我的问题是,我如何才能到最近的其他位置?从我已经获取的当前位置。

提前致谢。

【问题讨论】:

  • 转到this Link,这也有类似的问题。我想这会对你有所帮助。

标签: iphone ios ipad geocoding clgeocoder


【解决方案1】:

试试这个...

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

【讨论】:

  • 如何初始化 myLocation ?以及用什么代替 yourCurrentLocation ?我已经为当前位置编写了上面的代码 sn-p。
  • 查看tutorial 获取当前位置
  • 老兄,我正在获取当前位置,但是要写什么来代替 yourCurrentLocation ???我写了locationManager.location 代替yourCurrentLocation 对吗?
  • 大声笑,我问是因为我现在没有真正的设备,我正在模拟器中测试它。
  • CLLocationDistance nearByLocation=[locationManager.location distanceFromLocation:myLocation]; NSLog(@"nearByLocation=%f",nearByLocation); myLog 显示了一些点,例如 8230614.551295 它们是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-01
  • 1970-01-01
  • 2022-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多