0

我尝试通过 Geopoint 将 GeoPoint 转换为 Array 到 String 到 Array。我想用这个数组在地图套件中绘制折线。现在我可以转换为字符串但不能包含数组。我如何将所有字符串包含到数组中是否有另一种方法可以使用 GeoPoint 在地图套件中绘制折线?

- (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);


            }
        }
    }];
}
4

1 回答 1

0

您需要创建一个数组来添加字符串。如果您创建 aNSMutableArray并将其分配给muarray您,则基本上是在添加nil不执行任何操作的字符串。

        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);


        }
于 2014-04-12T21:51:07.773 回答