2011-04-27 2 views
0

나는 plist에서 Latitudes와 Longitudes가있는 장소가 길다. 사용자의 현재 위치의 X 거리 내에있는 장소의 tableView 만 보여주고 싶습니다. 'distanceFromLocation'을 사용할 수 있도록 platter 파일에서 & longs의 객체를 만드는 방법이 있습니까? 더 중요한 것은, 어떻게하면 X보다 적은 거리의 이름 만 배열에 표시 할 수 있습니까? 나는 일련 번호의 객체를 pls에있는 & longs로 만들 필요가 있다고 가정하고 있는데, 객체 distanceFrom이 X보다 적다면 배열에있는 객체를 처리하겠습니까?현재 위치에서 Plist 파일까지의 거리

도와주세요. 내가 지금하고 여기 어디에

가있다 : 나는 당신의 plist에서 이중 clubLatitude 라인

- (void)viewDidLoad { 
[super viewDidLoad]; 

    NSArray *clubArray = [NSArray arrayWithObjects:[self danceClubLocation], nil]; 
    self.tableData = clubArray; 
} 

-(CLLocation *)danceClubLocation 
{ 
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; 
    NSArray *array = [NSArray arrayWithContentsOfFile:plistPath]; 

    NSEnumerator *e = [array objectEnumerator]; 
    id object; 
    while ((object = [e nextObject])) { 
     double clubLatitude = [[array valueForKey:@"Latitude"] doubleValue]; 
     double clubLongitude = [[array valueForKey:@"Longitude"] doubleValue]; 
     CLLocation *clubLocation = [[CLLocation alloc] initWithLatitude:clubLatitude longitude:clubLongitude]; 
     if ([clubLocation distanceFromLocation:myLocation]<=50) { 
      return clubLocation; 
     } 
     else return nil; 
    } 
    return nil; 
} 

-(CLLocation *)myLocation 
{ 
    CLLocation *location = [locationManager location]; 
    CLLocationCoordinate2D coordinate = [location coordinate]; 
    NSNumber *myLatitude = [NSNumber numberWithDouble:coordinate.latitude]; 
    NSNumber *myLongitude = [NSNumber numberWithDouble:coordinate.longitude]; 
    double myLatitudeD = [myLatitude doubleValue]; 
    double myLongitudeD = [myLongitude doubleValue]; 
    myLocation = [[CLLocation alloc]initWithLatitude:myLatitudeD longitude:myLongitudeD]; 
    return myLocation; 
} 

답변

0

하면, 당신은 목록 (소스로 PLIST과 NSArray를) 반복해야하고이 같은 것입니다 :

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"latlong" ofType:@"plist"]; 
NSArray *array = [NSArray arrayWithContentsOfFile:plistPath]; 

NSEnumerator *e = [array objectEnumerator]; 
id object; 
while (object = [e nextObject]) { 
    // do something with object 
} 

그런 다음 당신은 당신이 원하는 것을 할 수 있습니다 (무슨 일이있어 제거 사용자와는 거리가 먼 곳).

+0

하지만 좌표는 한 번에 오른쪽 (lat & long)의 두 객체입니까? 어떻게 둘 다 열거합니까? X 거리보다 작은 것들만 표시하는 대신 다른 방법을 사용하면 모든 거리를 X 거리만큼 정렬하는 것이 더 쉬울까요? 그렇지 않으면 [e nextObject]에 대한 도움이 필요합니다. – Eric

+0

[e nextObject]는 컬렉션의 모든 객체를 반복합니다. NSArray를 NSDictionary에 사용하는 것부터 반복기 부분을 동일하게 사용하는 등 여러 가지 방법을 시도해 볼 수 있습니다. 분명히 iterating 또는 논리를 만드는 동안 그것을 정렬 할 수 있습니다. – ferostar

+0

컬렉션의 모든 개체를 반복하여, 내 plist 파일의 항목을 의미합니까? valueforKey @ "Latitude"와 @ "Longitude"만 보도록하려면 어떻게해야합니까? 배열이 끝나면 * e가 어떻게 표시됩니까? 고마움을 너무 많이하고 잘하면 나는 당신을 지금 괴롭히지 않을거야. – Eric

0

읽기에 오류가 발생,이 X로 이동할 수있는 거리에 사람을 끌어하고있을 것입니다 그들과 어떤 배열을 채우기 위해 반복 귀하의 테이블보기에 대한 데이터 소스? @DavidNeiss 말했듯이

+0

흠, 나는 어떻게 반복 할 지 모르겠다. – Eric

관련 문제