我有一个带有位置的表格视图,我想在按下按钮时按附近的位置过滤它们。我在想,当我按下按钮时,应用程序可以重新加载附近位置的表格视图,但我不知道如何进行过滤。
1 回答
1
假设您有一个NSArray对象CLLocation,我们称之为它locations,CLLocation *currenLocation它代表您当前的位置。
NSArray *sortedLocations = [locations sortedArrayUsingComparator:^(id obj1, id obj2) {
CLLocationDistance distance1 = [currentLocation distanceFromLocation: (CLLocation *)obj1];
CLLocationDistance distance2 = [currentLocation distanceFromLocation: (CLLocation *)obj2];
return distance1 - distance2;
}];
编辑:您可以使用对象CLLocationManager通过委托方法频繁更新用户的位置。您可以通过startUpdatingLocation. 选中此项可为您提供更多信息。
CLLocation如果您有地理位置,则可以通过– initWithLatitude:longitude:.
于 2013-06-05T23:31:05.137 回答