从我当前的位置获取最近的位置

Posted

技术标签:

【中文标题】从我当前的位置获取最近的位置【英文标题】: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,这也有类似的问题。我想这会对你有所帮助。 【参考方案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 它们是什么?

以上是关于从我当前的位置获取最近的位置的主要内容,如果未能解决你的问题,请参考以下文章

从我当前的位置找到最近的朋友

Firebase GeoFire,从我当前位置检索具有特定半径的帖子

使用当前位置时,我不断获取位置空值

如何通过iphone应用程序中的代码获取用户的当前位置?

打开android原生谷歌地图应用程序获取从当前位置开始的方向

Android - startActivityForResult 获取用户位置?