質問

ジオポイントをgeopointでrestrance to配列に変換しようとします。このアレイはマップキットで描画ポリラインに使用したいです。 これで、文字列に変換できますが、配列に含めることはできません。 どのようにしてすべての文字列を配列に含めることができます 地図キットにポリラインを描画するためにジオポイントを使用する別の方法はありますか?

- (void)updateLocations {
    CGFloat kilometers = self.radius/1000.0f;

    PFQuery *query = [PFQuery queryWithClassName:@"Location"];
    [query setLimit:1000];
    [query whereKey:@"location"
       nearGeoPoint:[PFGeoPoint geoPointWithLatitude:self.location.coordinate.latitude
                                           longitude:self.location.coordinate.longitude]
   withinKilometers:kilometers];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            static NSNumberFormatter *numberFormatter = nil;
            if (numberFormatter == nil) {
                numberFormatter = [[NSNumberFormatter alloc] init];
                numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
                numberFormatter.maximumFractionDigits = 6;
            }
            //NSArray *path = [objects valueForKey:@"location"]; //dictionary to array!!!
            //NSLog(@"%@ %@",objects,path);
            NSMutableArray *muarray;
            for (PFObject *object in objects) {

                PFGeoPoint *geoPoint = object[@"location"];
                NSString *string = [NSString stringWithFormat:@"{%@, %@}",
                                    [numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.latitude]],
                                    [numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.longitude]]];
                NSLog(@"%@",string);
                [muarray addObject:string]; //I'm try this but it's fail.
                NSLog(@"%@",muarray);


            }
        }
    }];
}
.

役に立ちましたか?

解決

文字列を追加するための配列を作成する必要があります。実行している場合は、NSMutableArrayを作成し、それをmuarrayに割り当てます。

        NSMutableArray *muarray = [NSMutableArray array];
        for (PFObject *object in objects) {

            PFGeoPoint *geoPoint = object[@"location"];
            NSString *string = [NSString stringWithFormat:@"{%@, %@}",
                                [numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.latitude]],
                                [numberFormatter stringFromNumber:[NSNumber numberWithDouble:geoPoint.longitude]]];
            NSLog(@"%@",string);
            [muarray addObject:string]; //I'm try this but it's fail.
            NSLog(@"%@",muarray);


        }
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top