나는 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;
}
하지만 좌표는 한 번에 오른쪽 (lat & long)의 두 객체입니까? 어떻게 둘 다 열거합니까? X 거리보다 작은 것들만 표시하는 대신 다른 방법을 사용하면 모든 거리를 X 거리만큼 정렬하는 것이 더 쉬울까요? 그렇지 않으면 [e nextObject]에 대한 도움이 필요합니다. – Eric
[e nextObject]는 컬렉션의 모든 객체를 반복합니다. NSArray를 NSDictionary에 사용하는 것부터 반복기 부분을 동일하게 사용하는 등 여러 가지 방법을 시도해 볼 수 있습니다. 분명히 iterating 또는 논리를 만드는 동안 그것을 정렬 할 수 있습니다. – ferostar
컬렉션의 모든 개체를 반복하여, 내 plist 파일의 항목을 의미합니까? valueforKey @ "Latitude"와 @ "Longitude"만 보도록하려면 어떻게해야합니까? 배열이 끝나면 * e가 어떻게 표시됩니까? 고마움을 너무 많이하고 잘하면 나는 당신을 지금 괴롭히지 않을거야. – Eric