您可以使用CLLocationManagerDelegate的locationManager:didUpdateLocations:Method。
当用户的位置将更新时调用此方法,以便您可以调用您的方法在用户当前位置的tableview中显示数据。
下面是一些排序你的arryOfLocation的代码。
for (int i = 0; i < arrySortByLocation.count; i++)
{
//Current Location Details
NSMutableDictionary *dict = [[arrySortByLocation objectAtIndex:i] mutableCopy];
CLLocationDegrees latitude = [dict[@"city_lat"] doubleValue];
CLLocationDegrees longitude = [dict[@"city_lng"] doubleValue];
CLLocation *location = [[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
CLLocationDistance distance = [appDele.userLocation distanceFromLocation:location];
dict[@"distance"] = [@(distance) stringValue];
//Storing as string since latitude and longitude is also string values
//Since its a dictionary storing as NSNumber is better
[arrySearchLocation setObject:dict atIndexedSubscript:i];
}
//sorting based on distance
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"distance.doubleValue" ascending:YES];
[arrySortByLocation sortUsingDescriptors:@[descriptor]];
}
希望这将帮助你..
有啥问题? – 2015-04-03 05:25:23
我问我是否应该在应用程序开始时或在查看表视图中的特定位置时计算从当前位置到表视图中所有位置的所有距离?何时应该在用户旅行时更新这些距离? – user2253546 2015-04-03 05:28:56