从我当前的位置获取最近的位置 [英] get nearest locations from my current location

查看:193
本文介绍了从我当前的位置获取最近的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently developing a mobile application for iOS which consists a part that requires to determine the users current location and from current location, i want to find nearest locations.

有没有办法实现这个?

我已经做了一些编码来查找用户的当前位置。
这是我的代码片段,

I have done some coding for finding current location of user. here is my code snippet,

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

但我的问题是,我将如何获得最近的其他位置?从我目前所在的位置开始。

But my problem is, how will i get nearest other locations ?? from my current location which i already fetched.

提前致谢。

推荐答案

试试这个......

Try this...

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

这篇关于从我当前的位置获取最近的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆