plistに緯度と経度を含む場所の長いリストがあります。ユーザーの現在の場所から X の距離内にある場所の tableView のみを表示したいと考えています。「distanceFromLocation」を使用できるように、plist ファイルの緯度と経度からオブジェクトを作成する方法はありますか? さらに重要なことに、現在からの距離が X 未満の名前のみを表示する配列を取得するにはどうすればよいですか? plist で緯度と経度から一連のオブジェクトを作成する必要があると想定しています。次に、オブジェクトの distanceFrom が X より小さい場合は、配列でオブジェクトを作成します。正しいですか?
助けてください。
これが現在の状況です: double 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;
}