0

)

現在のオブジェクトが restaurantDetail という名前の場合、私はこのようにコーディネイトにアクセスできます。

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/fc8q69ここにログがあります。最後の座標セットはレストランの 1 つと同じ私の場所です

4

1 に答える 1

2
   for(i=0;i<[array_res count];i++){
    if([clloc distanceFromLocation:[array_res objectatindex:i]<100])
    {
    //if less than 100meters
    //then add object in this array
    [near_by_user addobject:[array_res objectatindex:i];
    }
    }

please add this code.if you have any clarification update here
于 2013-11-10T18:34:30.090 に答える