我有一個nsmutable數組的朋友list.each有他們的經緯度& longs.I想排序與他們距離autor.I的距離的上升速度數組,我發現了朋友與作者的距離值,現在我要排序他們distances.This的上升數組如何我做的是,'如何按距離升序排序一個NSmutable數組?
for(int i=0;i<[searchfriendarray count];i++)
{
NSDictionary *payload =[searchfriendarray objectAtIndex:i];
NSLog(@"%@",payload);
NSString *memberid = [payload objectForKey:@"userID"];
CLLocation *locationofauthor;
CLLocation *locationoffriends;
if([memberid isEqualToString:uidstr])
{
NSString *latofauthor = [payload objectForKey:@"latitude"];
NSString *longofauthor=[payload objectForKey:@"longitude"];
double latofauthordouble = [latofauthor doubleValue];
double longofauthordouble=[longofauthor doubleValue];;
locationofauthor = [[CLLocation alloc] initWithLatitude:latofauthordouble longitude:longofauthordouble];
}
else
{
NSString *latoffriends = [payload objectForKey:@"latitude"];
NSString *longoffriends=[payload objectForKey:@"longitude"];
double latoffriendsdouble = [latoffriends doubleValue];
double longoffriendsdouble=[longoffriends doubleValue];;
locationoffriends = [[CLLocation alloc] initWithLatitude:latoffriendsdouble longitude:longoffriendsdouble];
}
CLLocationDistance distance = [locationofauthor distanceFromLocation:locationoffriends];
}
`任何機構可以幫我把我的距離的ascecending順序排列排序?
你是從CoreData獲取這個數組嗎? –
否....從服務中返回? – hacker
你的主要問題是什麼?你在CLLocationDistance距離中獲得所有的距離。將其存儲在數組中。這是雙重價值。你不知道如何分類雙重價值? – CRDave