作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个应用程序,其中我有一个位置坐标。(即纬度和经度)。然后我有一个 friend 列表及其(纬度和经度)。
I need to sort my friends array according to the condition that who is nearest to me comes first
.我有他们的和我的经纬度。有人能帮我实现这个吗?
最佳答案
CLLocation *myLoc = [[CLLocation alloc] initWithLatitude:42.5000 longitude:1.5000];
NSArray *arr = [NSArray arrayWithObjects:
[[CLLocation alloc] initWithLatitude:42.5000 longitude:1.5000],
[[CLLocation alloc] initWithLatitude:24.0000 longitude:54.0000],
[[CLLocation alloc] initWithLatitude:33.0000 longitude:65.0000],
[[CLLocation alloc] initWithLatitude:17.0500 longitude:-61.8000],
[[CLLocation alloc] initWithLatitude:18.2500 longitude:-63.1667],
[[CLLocation alloc] initWithLatitude:41.0000 longitude:20.0000],
[[CLLocation alloc] initWithLatitude:40.0000 longitude:45.0000],
nil
];
CLLocation *nearestLoc = nil;
CLLocationDistance nearestDis = DBL_MAX;
for (CLLocation *loc in arr) {
CLLocationDistance distance = [myLoc distanceFromLocation:loc];
if (nearestDis > distance) {
nearestLoc = loc;
nearestDis = distance;
}
}
关于iphone - 如何从我的经纬度找出最近的用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14659808/
我是一名优秀的程序员,十分优秀!