)
我有一个可变的 restaurantObjects 数组,序列化了 json 数据,如果当前对象被命名为 restaurantDetail,我可以像这样访问 corrdinates
float x = [[restaurantDetail.coordinates objectAtIndex:0] floatValue];
float y = [[restaurantDetail.coordinates objectAtIndex:1] floatValue];
所以我想提取靠近用户位置的餐馆并将它们存储到数组中
如果用户更改位置数组也应该更新
我真的很想得到帮助,因为我在这里完全迷失了
我试过这种形式 Muthub Ram
- (void) checkIfInRegion{
Restaurant * currentRestaurant;
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
for(int i=0;i<[restaurantsArray count];i++){
currentRestaurant = [restaurantsArray objectAtIndex:i];
//NSLog(@"%@",currentRestaurant.coordinates);
CLLocation * currentRestLoc = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake([[currentRestaurant.coordinates objectAtIndex:0] floatValue], [[currentRestaurant.coordinates objectAtIndex:1] floatValue])
altitude:0
horizontalAccuracy:0
verticalAccuracy:0
timestamp:[NSDate date]];
NSLog(@"%@",currentRestLoc);
if([locationManager.location distanceFromLocation:currentRestLoc] <100)
{
//if less than 100meters
//then add object in this array
[near_by_user addObject:[restaurantsArray objectAtIndex:i]];
}
}
NSLog(@"%@",locationManager.location);
NSLog(@"restaurants near%@",near_by_user);
[locationManager stopUpdatingLocation];
}
我得到所有坐标形式的位置,但我没有得到 near_by_user 数组中的任何对象(它仍然是空的)
http://pastebin.com/fc8q69Le这里是日志,最后一组坐标是我的位置,与其中一家餐厅相同