我有一个长长的列表,上面有纬度和经度。我只想显示距离用户当前位置X距离内的地点的tableView。有没有办法从plist文件中的经纬度创建对象,这样我就可以使用'distanceFromLocation‘了?更重要的是,如何让数组只显示与当前距离小于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;
}发布于 2011-04-28 02:34:37
正如@DavidNeiss所说,你必须遍历列表(一个以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
}然后你就可以做你想做的事情了(移除远离用户的东西或其他东西)。
发布于 2011-04-28 02:20:19
读入你的plist,迭代它以拉出X距离内的数组,并用它们填充任何将成为表视图数据源的数组?
https://stackoverflow.com/questions/5808513
复制相似问题